Skip to content

Commit

Permalink
use the official $deprecated property now (#1099)
Browse files Browse the repository at this point in the history
* use the official $deprecated property now

* added changeset
  • Loading branch information
lukasoppermann authored Dec 4, 2024
1 parent e00e02e commit 80cc57c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 207 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-donuts-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/primitives': patch
---

Replace `deprecated` prop with `$deprecated` which is the w3c standard
189 changes: 0 additions & 189 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions src/filters/isDeprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import {isDeprecated} from './isDeprecated.js'

describe('Filter: isDeprecated', () => {
it('Returns true if depreacted property is true', () => {
expect(isDeprecated(getMockToken({deprecated: true}))).toStrictEqual(true)
expect(isDeprecated(getMockToken({$deprecated: true}))).toStrictEqual(true)
})

it('Returns true if depreacted property is a string', () => {
expect(isDeprecated(getMockToken({deprecated: 'pumpkin'}))).toStrictEqual(true)
expect(isDeprecated(getMockToken({$deprecated: 'pumpkin'}))).toStrictEqual(true)
})

it('Returns false if deprecated is falsy', () => {
expect(isDeprecated(getMockToken({deprecated: false}))).toStrictEqual(false)
expect(isDeprecated(getMockToken({deprecated: null}))).toStrictEqual(false)
expect(isDeprecated(getMockToken({deprecated: undefined}))).toStrictEqual(false)
expect(isDeprecated(getMockToken({$deprecated: false}))).toStrictEqual(false)
expect(isDeprecated(getMockToken({$deprecated: null}))).toStrictEqual(false)
expect(isDeprecated(getMockToken({$deprecated: undefined}))).toStrictEqual(false)
})

it('Returns false if no deprecated property exists', () => {
Expand All @@ -22,19 +22,19 @@ describe('Filter: isDeprecated', () => {

const inputArray = [
getMockToken({
deprecated: true,
$deprecated: true,
}),
getMockToken({
deprecated: '{scale.yellow}',
$deprecated: '{scale.yellow}',
}),
getMockToken({
deprecated: null,
$deprecated: null,
}),
getMockToken({
deprecated: false,
$deprecated: false,
}),
getMockToken({
deprecated: undefined,
$deprecated: undefined,
}),
getMockToken({
value: 'pumpkin',
Expand All @@ -43,10 +43,10 @@ describe('Filter: isDeprecated', () => {

const expectedOutput = [
getMockToken({
deprecated: true,
$deprecated: true,
}),
getMockToken({
deprecated: '{scale.yellow}',
$deprecated: '{scale.yellow}',
}),
]

Expand Down
2 changes: 1 addition & 1 deletion src/filters/isDeprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import type {TransformedToken} from 'style-dictionary/types'
* @returns boolean
*/
export const isDeprecated = (token: TransformedToken): boolean => {
return token.deprecated === true || typeof token.deprecated === 'string'
return token.$deprecated === true || typeof token.$deprecated === 'string'
}
2 changes: 1 addition & 1 deletion src/schemas/baseToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import {z} from 'zod'
export const baseToken = z
.object({
$description: z.string().optional(),
deprecated: z.union([z.string(), z.boolean()]).optional(),
$deprecated: z.union([z.string(), z.boolean()]).optional(),
})
.strict()
6 changes: 3 additions & 3 deletions src/transformers/jsonDeprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('Transformer: jsonDeprecated', () => {
it('Replaces token value with `null` if deprecated is set to `true`', () => {
const item = getMockToken({
value: 'tokenName',
deprecated: true,
$deprecated: true,
})
const expectedOutput = null
expect(jsonDeprecated.transform(item, {}, {})).toStrictEqual(expectedOutput)
Expand All @@ -14,7 +14,7 @@ describe('Transformer: jsonDeprecated', () => {
it('Replaces token value with deprecated value if deprecated is a `string`', () => {
const item = getMockToken({
value: 'tokenName',
deprecated: `token.pumpkin`,
$deprecated: `token.pumpkin`,
})
const expectedOutput = 'token.pumpkin'
expect(jsonDeprecated.transform(item, {}, {})).toStrictEqual(expectedOutput)
Expand All @@ -23,7 +23,7 @@ describe('Transformer: jsonDeprecated', () => {
it('Replaces token value with deprecated value if deprecated is a `string` and removes {}', () => {
const item = getMockToken({
value: 'tokenName',
deprecated: `{token.pumpkin}`,
$deprecated: `{token.pumpkin}`,
})
const expectedOutput = 'token.pumpkin'
expect(jsonDeprecated.transform(item, {}, {})).toStrictEqual(expectedOutput)
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/jsonDeprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export const jsonDeprecated: Transform = {
transitive: true,
filter: isDeprecated,
transform: (token: TransformedToken) =>
typeof token.deprecated === 'string' ? token.deprecated.replace(/[{}]/g, '') : null,
typeof token.$deprecated === 'string' ? token.$deprecated.replace(/[{}]/g, '') : null,
}

0 comments on commit 80cc57c

Please sign in to comment.