Skip to content

Commit e16b222

Browse files
committed
fix(badge): separate S1/S2 API in alternate approach
1 parent 3d80eca commit e16b222

File tree

3 files changed

+103
-20
lines changed

3 files changed

+103
-20
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ import { SizedMixin, SpectrumElement } from '@swc/core/shared/base';
1616
import { ObserveSlotPresence } from '@swc/core/shared/observe-slot-presence';
1717
import { ObserveSlotText } from '@swc/core/shared/observe-slot-text';
1818

19-
export const BADGE_VARIANTS = [
19+
export const BADGE_VARIANTS_SEMANTIC = [
2020
'accent',
2121
'neutral',
2222
'informative',
2323
'positive',
2424
'negative',
2525
'notice',
26+
] as const;
27+
28+
export const BADGE_VARIANTS_COLOR = [
2629
'fuchsia',
2730
'indigo',
2831
'magenta',
@@ -37,11 +40,11 @@ export const BADGE_VARIANTS = [
3740
'green',
3841
'cyan',
3942
'blue',
40-
'pink',
41-
'turquoise',
42-
'brown',
43-
'cinnamon',
44-
'silver',
43+
] as const;
44+
45+
export const BADGE_VARIANTS = [
46+
...BADGE_VARIANTS_SEMANTIC,
47+
...BADGE_VARIANTS_COLOR,
4548
] as const;
4649
export type BadgeVariant = (typeof BADGE_VARIANTS)[number];
4750
export const FIXED_VALUES = [
@@ -55,8 +58,6 @@ export type FixedValues = (typeof FIXED_VALUES)[number];
5558
/**
5659
* @element sp-badge-base
5760
* @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.
6061
* @property {FixedValues} fixed - The fixed position of the badge.
6162
* @property {string[]} customStyles - The custom styles of the badge.
6263
*/
@@ -69,12 +70,6 @@ export abstract class BadgeBase extends SizedMixin(
6970
@property({ type: String, reflect: true })
7071
public variant: BadgeVariant = 'informative';
7172

72-
@property({ type: Boolean, reflect: true })
73-
public subtle: boolean = false;
74-
75-
@property({ type: Boolean, reflect: true })
76-
public outline: boolean = false;
77-
7873
@property({ type: String, reflect: true })
7974
public fixed?: FixedValues;
8075

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,39 @@
1111
*/
1212

1313
import { CSSResultArray, html, TemplateResult } from 'lit';
14+
import { property } from 'lit/decorators.js';
1415
import { classMap } from 'lit/directives/class-map.js';
1516
import { when } from 'lit/directives/when.js';
1617

17-
import { BadgeBase } from '@swc/core/components/badge';
18+
import {
19+
BADGE_VARIANTS_COLOR as BADGE_VARIANTS_COLOR_BASE,
20+
BADGE_VARIANTS_SEMANTIC,
21+
BadgeBase,
22+
} from '@swc/core/components/badge';
23+
24+
export const BADGE_VARIANTS_COLOR = [
25+
...BADGE_VARIANTS_COLOR_BASE,
26+
'pink',
27+
'turquoise',
28+
'brown',
29+
'cinnamon',
30+
'silver',
31+
] as const;
32+
33+
export const BADGE_VARIANTS = [
34+
...BADGE_VARIANTS_SEMANTIC,
35+
...BADGE_VARIANTS_COLOR,
36+
] as const;
37+
export type BadgeVariant = (typeof BADGE_VARIANTS)[number];
1838

1939
import styles from './badge.css';
2040

2141
// Export types and values to avoid breaking changes
22-
export { BADGE_VARIANTS, FIXED_VALUES } from '@swc/core/components/badge';
23-
export type { BadgeVariant, FixedValues } from '@swc/core/components/badge';
42+
export {
43+
BADGE_VARIANTS_SEMANTIC,
44+
FIXED_VALUES,
45+
} from '@swc/core/components/badge';
46+
export type { FixedValues } from '@swc/core/components/badge';
2447

2548
/**
2649
* A badge component that displays short, descriptive information about an element.
@@ -32,6 +55,12 @@ export type { BadgeVariant, FixedValues } from '@swc/core/components/badge';
3255
* @github https://github.com/adobe/spectrum-web-components/tree/main/...
3356
* @figma https://www.figma.com/design/Mngz9H7WZLbrCvGQf3GnsY/S2-%2F-Desktop?node-id=36806-6551
3457
*
58+
* @property {BadgeVariant} variant - The variant of the badge.
59+
* @property {boolean} subtle - Whether the badge is subtle.
60+
* @property {boolean} outline - Whether the badge is outlined.
61+
* @property {FixedValues} fixed - The fixed position of the badge.
62+
* @property {string[]} customStyles - The custom styles of the badge.
63+
*
3564
* @slot - Text label of the badge
3665
* @slot icon - Optional icon that appears to the left of the label
3766
*
@@ -48,6 +77,12 @@ export type { BadgeVariant, FixedValues } from '@swc/core/components/badge';
4877
* </swc-badge>
4978
*/
5079
export class Badge extends BadgeBase {
80+
@property({ type: Boolean, reflect: true })
81+
public subtle: boolean = false;
82+
83+
@property({ type: Boolean, reflect: true })
84+
public outline: boolean = false;
85+
5186
public static override get styles(): CSSResultArray {
5287
return [styles];
5388
}

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
import { html } from 'lit';
1414
import type { Meta, StoryObj } from '@storybook/web-components';
1515

16-
import { BADGE_VARIANTS, FIXED_VALUES } from '@swc/components/badge';
16+
import {
17+
BADGE_VARIANTS,
18+
BADGE_VARIANTS_COLOR,
19+
BADGE_VARIANTS_SEMANTIC,
20+
FIXED_VALUES,
21+
} from '@swc/components/badge';
1722

1823
import '@swc/components/badge';
1924

@@ -33,9 +38,17 @@ const meta: Meta = {
3338
control: { type: 'select' },
3439
options: ['s', 'm', 'l', 'xl'],
3540
},
41+
subtle: {
42+
control: { type: 'boolean' },
43+
},
44+
outline: {
45+
control: { type: 'boolean' },
46+
},
3647
},
3748
args: {
3849
variant: 'informative',
50+
subtle: false,
51+
outline: false,
3952
},
4053
};
4154

@@ -57,10 +70,22 @@ export const Default: Story = {
5770
`,
5871
};
5972

60-
export const Variants: Story = {
73+
export const SemanticVariants: Story = {
6174
render: () => html`
6275
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
63-
${BADGE_VARIANTS.map(
76+
${BADGE_VARIANTS_SEMANTIC.map(
77+
(variant) => html`
78+
<swc-badge variant="${variant}">${variant}</swc-badge>
79+
`
80+
)}
81+
</div>
82+
`,
83+
};
84+
85+
export const ColorVariants: Story = {
86+
render: () => html`
87+
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
88+
${BADGE_VARIANTS_COLOR.map(
6489
(variant) => html`
6590
<swc-badge variant="${variant}">${variant}</swc-badge>
6691
`
@@ -88,3 +113,31 @@ export const WithIcon: Story = {
88113
</swc-badge>
89114
`,
90115
};
116+
117+
export const Subtle: Story = {
118+
render: () => html`
119+
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
120+
${BADGE_VARIANTS.map(
121+
(variant) => html`
122+
<swc-badge variant="${variant}" subtle>
123+
${variant}
124+
</swc-badge>
125+
`
126+
)}
127+
</div>
128+
`,
129+
};
130+
131+
export const Outline: Story = {
132+
render: () => html`
133+
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
134+
${BADGE_VARIANTS_SEMANTIC.map(
135+
(variant) => html`
136+
<swc-badge variant="${variant}" outline>
137+
${variant}
138+
</swc-badge>
139+
`
140+
)}
141+
</div>
142+
`,
143+
};

0 commit comments

Comments
 (0)