Skip to content

Commit

Permalink
chore: remove deprecated badge values (#4742)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubencarvalho authored Oct 16, 2024
1 parent d428f8d commit 5e7a374
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 102 deletions.
19 changes: 2 additions & 17 deletions packages/badge/src/Badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,14 @@ export const BADGE_VARIANTS = [
'cyan',
'blue',
] as const;
export type BadgeVariant = typeof BADGE_VARIANTS[number];
export const FIXED_VALUES_DEPRECATED = ['top', 'bottom', 'left', 'right'];
export type BadgeVariant = (typeof BADGE_VARIANTS)[number];
export const FIXED_VALUES = [
'inline-start',
'inline-end',
'block-start',
'block-end',
] as const;
export type FixedValues =
| typeof FIXED_VALUES[number]
| typeof FIXED_VALUES_DEPRECATED[number];
export type FixedValues = (typeof FIXED_VALUES)[number];

/**
* @element sp-badge
Expand All @@ -82,18 +79,6 @@ export class Badge extends SizedMixin(
public set fixed(fixed: FixedValues | undefined) {
if (fixed === this.fixed) return;
const oldValue = this.fixed;
if (window.__swc.DEBUG) {
if (fixed && FIXED_VALUES_DEPRECATED.includes(fixed)) {
window.__swc.warn(
this,
`The following values for "fixed" in <${this.localName}> have been deprecated. They will be removed in a future release.`,
'https://opensource.adobe.com/spectrum-web-components/components/badge/#fixed',
{
issues: [...FIXED_VALUES_DEPRECATED],
}
);
}
}
this._fixed = fixed;
if (fixed) {
this.setAttribute('fixed', fixed);
Expand Down
22 changes: 0 additions & 22 deletions packages/badge/src/badge.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,6 @@ governing permissions and limitations under the License.
align-items: center;
}

/* Marked as deprecated, remove in a future release */

:host([fixed='left']) {
border-end-start-radius: 0;
border-start-start-radius: 0; /* .spectrum-Badge--fixed-inline-start */
}

:host([fixed='right']) {
border-end-end-radius: 0;
border-start-end-radius: 0; /* .spectrum-Badge--fixed-inline-end */
}

:host([fixed='top']) {
border-start-end-radius: 0;
border-start-start-radius: 0; /* .spectrum-Badge--fixed-block-start */
}

:host([fixed='bottom']) {
border-end-end-radius: 0;
border-end-start-radius: 0; /* .spectrum-Badge--fixed-block-end */
}

/* cascade badge's size to its icon */

:host([size='xs']) {
Expand Down
90 changes: 27 additions & 63 deletions packages/badge/test/badge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@ import { testForLitDevWarnings } from '../../../test/testing-helpers.js';
describe('Badge', () => {
testForLitDevWarnings(
async () =>
await fixture<Badge>(
html`
<sp-badge>
<sp-icon-checkmark-circle
slot="icon"
></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
`
)
await fixture<Badge>(html`
<sp-badge>
<sp-icon-checkmark-circle
slot="icon"
></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
`)
);
it('manages `fixed` attribute', async () => {
const el = await fixture<Badge>(
html`
<sp-badge>Label only</sp-badge>
`
);
const el = await fixture<Badge>(html`
<sp-badge>Label only</sp-badge>
`);

expect(el.fixed).to.be.undefined;

Expand Down Expand Up @@ -76,33 +72,29 @@ describe('Badge', () => {
});

it('loads default badge accessibly', async () => {
const el = await fixture<Badge>(
html`
<sp-badge>
<sp-icon-checkmark-circle
slot="icon"
></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
`
);
const el = await fixture<Badge>(html`
<sp-badge>
<sp-icon-checkmark-circle
slot="icon"
></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
`);

await elementUpdated(el);

await expect(el).to.be.accessible();
expect(consoleWarnStub.called).to.be.false;
});
it('warns in Dev Mode when sent an incorrect `variant`', async () => {
const el = await fixture<Badge>(
html`
<sp-badge variant="other">
<sp-icon-checkmark-circle
slot="icon"
></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
`
);
const el = await fixture<Badge>(html`
<sp-badge variant="other">
<sp-icon-checkmark-circle
slot="icon"
></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
`);

await elementUpdated(el);

Expand All @@ -120,33 +112,5 @@ describe('Badge', () => {
},
});
});
it('warns in Dev Mode when sent a deprecated value for `fixed`', async () => {
const el = await fixture<Badge>(
html`
<sp-badge fixed="top">
<sp-icon-checkmark-circle
slot="icon"
></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
`
);

await elementUpdated(el);

expect(consoleWarnStub.called).to.be.true;
const spyCall = consoleWarnStub.getCall(0);
expect(
(spyCall.args.at(0) as string).includes('"fixed"'),
'confirm fixed-centric message'
).to.be.true;
expect(spyCall.args.at(-1), 'confirm `data` shape').to.deep.equal({
data: {
localName: 'sp-badge',
type: 'api',
level: 'default',
},
});
});
});
});

0 comments on commit 5e7a374

Please sign in to comment.