Skip to content

Commit 76955a7

Browse files
committed
feat(badge): s2 styling and render brought in
1 parent bcd577d commit 76955a7

File tree

7 files changed

+756
-929
lines changed

7 files changed

+756
-929
lines changed

second-gen/packages/core/components/badge/Badge.base.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export const BADGE_VARIANTS = [
3737
'green',
3838
'cyan',
3939
'blue',
40+
'pink',
41+
'turquoise',
42+
'brown',
43+
'cinnamon',
44+
'silver',
4045
] as const;
4146
export type BadgeVariant = (typeof BADGE_VARIANTS)[number];
4247
export const FIXED_VALUES = [
@@ -49,8 +54,11 @@ export type FixedValues = (typeof FIXED_VALUES)[number];
4954

5055
/**
5156
* @element sp-badge-base
52-
* @slot - The text label to display in the badge.
53-
* @slot icon - The icon to display in the badge.
57+
* @property {BadgeVariant} variant - The variant of the badge.
58+
* @property {boolean} subtle - Whether the badge is subtle.
59+
* @property {boolean} outline - Whether the badge is outlined.
60+
* @property {FixedValues} fixed - The fixed position of the badge.
61+
* @property {string[]} customStyles - The custom styles of the badge.
5462
*/
5563
export abstract class BadgeBase extends SizedMixin(
5664
ObserveSlotText(ObserveSlotPresence(SpectrumElement, '[slot="icon"]'), ''),
@@ -61,26 +69,14 @@ export abstract class BadgeBase extends SizedMixin(
6169
@property({ type: String, reflect: true })
6270
public variant: BadgeVariant = 'informative';
6371

64-
@property({ reflect: true })
65-
public get fixed(): FixedValues | undefined {
66-
return this._fixed;
67-
}
72+
@property({ type: Boolean, reflect: true })
73+
public subtle: boolean = false;
6874

69-
public set fixed(fixed: FixedValues | undefined) {
70-
if (fixed === this.fixed) {
71-
return;
72-
}
73-
const oldValue = this.fixed;
74-
this._fixed = fixed;
75-
if (fixed) {
76-
this.setAttribute('fixed', fixed);
77-
} else {
78-
this.removeAttribute('fixed');
79-
}
80-
this.requestUpdate('fixed', oldValue);
81-
}
75+
@property({ type: Boolean, reflect: true })
76+
public outline: boolean = false;
8277

83-
private _fixed?: FixedValues;
78+
@property({ type: String, reflect: true })
79+
public fixed?: FixedValues;
8480

8581
protected get hasIcon(): boolean {
8682
return this.slotContentIsPresent;

second-gen/packages/core/components/progress-circle/ProgressCircle.base.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ export abstract class ProgressCircleBase extends SizedMixin(SpectrumElement, {
3434

3535
/**
3636
* Static color variant for use on different backgrounds.
37-
* When set to 'white', the component uses white styling for dark backgrounds.
37+
* When set to 'white', the component uses white styling for images with a dark tinted background.
38+
* When set to 'black', the component uses black styling for images with a light tinted background.
3839
*/
3940
@property({ reflect: true, attribute: 'static-color' })
40-
public staticColor?: 'white';
41+
public staticColor?: 'white' | 'black';
4142

4243
/**
4344
* Progress value from 0 to 100.
@@ -46,6 +47,24 @@ export abstract class ProgressCircleBase extends SizedMixin(SpectrumElement, {
4647
@property({ type: Number })
4748
public progress = 0;
4849

50+
/**
51+
* Stroke width for the progress circle.
52+
*/
53+
@property({ type: Number, reflect: false })
54+
public get strokeWidth(): number {
55+
return this._strokeWidth;
56+
}
57+
58+
public set strokeWidth(customWidth: unknown) {
59+
if (customWidth && customWidth instanceof Number) {
60+
this._strokeWidth = customWidth as number;
61+
}
62+
63+
this._strokeWidth = this.size === 's' ? 2 : this.size === 'l' ? 4 : 3;
64+
}
65+
66+
private _strokeWidth: number = 2;
67+
4968
@query('slot')
5069
private slotEl!: HTMLSlotElement;
5170

second-gen/packages/swc/components/badge/Badge.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { CSSResultArray, html, nothing, TemplateResult } from 'lit';
13+
import { CSSResultArray, html, TemplateResult } from 'lit';
14+
import { classMap } from 'lit/directives/class-map.js';
15+
import { when } from 'lit/directives/when.js';
1416

1517
import { BadgeBase } from '@swc/core/components/badge';
1618

@@ -28,7 +30,7 @@ export type { BadgeVariant, FixedValues } from '@swc/core/components/badge';
2830
* @since 1.0.0
2931
* @status stable
3032
* @github https://github.com/adobe/spectrum-web-components/tree/main/...
31-
* @figma https://www.figma.com/design/...
33+
* @figma https://www.figma.com/design/Mngz9H7WZLbrCvGQf3GnsY/S2-%2F-Desktop?node-id=36806-6551
3234
*
3335
* @slot - Text label of the badge
3436
* @slot icon - Optional icon that appears to the left of the label
@@ -52,16 +54,36 @@ export class Badge extends BadgeBase {
5254

5355
protected override render(): TemplateResult {
5456
return html`
55-
${this.hasIcon
56-
? html`
57-
<slot
58-
name="icon"
59-
?icon-only=${!this.slotHasContent}
60-
></slot>
61-
`
62-
: nothing}
63-
<div class="label">
64-
<slot></slot>
57+
<div
58+
class=${classMap({
59+
['spectrum-Badge']: true,
60+
[`spectrum-Badge--size${this.size?.toUpperCase()}`]:
61+
typeof this.size !== 'undefined',
62+
[`spectrum-Badge--${this.variant}`]:
63+
typeof this.variant !== 'undefined',
64+
[`spectrum-Badge--subtle`]: this.subtle,
65+
[`spectrum-Badge--outline`]: this.outline,
66+
[`spectrum-Badge--fixed-${this.fixed}`]:
67+
typeof this.fixed !== 'undefined',
68+
})}
69+
>
70+
${when(
71+
this.hasIcon,
72+
() => html`
73+
<div
74+
class=${classMap({
75+
[`spectrum-Badge-icon`]: true,
76+
[`spectrum-Badge-icon--no-label`]:
77+
!this.slotHasContent,
78+
})}
79+
>
80+
<slot name="icon"></slot>
81+
</div>
82+
`
83+
)}
84+
<div class="spectrum-Badge-label">
85+
<slot></slot>
86+
</div>
6587
</div>
6688
`;
6789
}

0 commit comments

Comments
 (0)