Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/mean-elephants-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@shopify/polaris-tokens': patch
'@shopify/polaris-migrator': minor
---

Refactored exported alias and scale types in `breakpoints`, `depth`, `font`, `motion`, `shape`, `spacing`, and `zIndex`.
Added `isKeyOf` to exports from `polaris-migrator` package.
2 changes: 2 additions & 0 deletions polaris-migrator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export type {CLIConfig} from './constants';

export {migrate} from './migrate';
export type {MigrateOptions} from './migrate';

export {isKeyOf} from './utilities/type-guards';
9 changes: 2 additions & 7 deletions polaris-tokens/src/token-groups/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,5 @@ export const breakpoints = {
export type BreakpointsTokenGroup = TokenGroup<typeof breakpoints>;
export type BreakpointsTokenName = keyof BreakpointsTokenGroup;

// e.g. "xs" | "sm" | "md" | "lg" | "xl"
export type BreakpointsAlias = Extract<
BreakpointsTokenName,
`breakpoints-${string}`
> extends `breakpoints-${infer Alias}`
? Alias
: never;
export const breakpointsAlias = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
export type BreakpointsAlias = typeof breakpointsAlias[number];
20 changes: 13 additions & 7 deletions polaris-tokens/src/token-groups/depth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ export const depth = {
export type DepthTokenGroup = TokenGroup<typeof depth>;
export type DepthTokenName = keyof DepthTokenGroup;

// temporary until shadows prefix is removed
type ShadowsTokenName = Exclude<DepthTokenName, `shadows-${string}`>;

// e.g. "transparent" | "faint" | "base" | "deep" | ...
export type DepthShadowAlias = ShadowsTokenName extends `shadow-${infer Scale}`
? Scale
: never;
export const depthShadowAlias = [
'base',
'transparent',
'faint',
'deep',
'button',
'top-bar',
'card',
'popover',
'layer',
'modal',
] as const;
export type DepthShadowAlias = typeof depthShadowAlias[number];
41 changes: 20 additions & 21 deletions polaris-tokens/src/token-groups/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,25 @@ export const font = {
export type FontTokenGroup = TokenGroup<typeof font>;
export type FontTokenName = keyof FontTokenGroup;

// e.g. "400" | "500" | "600" | "700" | "100" | ...
export type FontSizeScale = Extract<
FontTokenName,
`font-size-${number}`
> extends `font-size-${infer Scale}`
? Scale
: never;
export const fontSizeScale = [
'75',
'100',
'200',
'300',
'400',
'500',
'600',
'700',
] as const;
export type FontSizeScale = typeof fontSizeScale[number];

// e.g. "1" | "2" | "3" | "4" | "5" | "6" | "7"
export type FontLineHeightScale = Extract<
FontTokenName,
`font-line-height-${number}`
> extends `font-line-height-${infer Scale}`
? Scale
: never;
export const fontLineHeightScale = ['1', '2', '3', '4', '5', '6', '7'] as const;
export type FontLineHeightScale = typeof fontLineHeightScale[number];

// e.g. "bold" | "regular" | "medium" | "semibold"
export type FontWeightAlias = Extract<
FontTokenName,
`font-weight-${string}`
> extends `font-weight-${infer Alias}`
? Alias
: never;
export const fontWeightAlias = [
'regular',
'medium',
'semibold',
'bold',
] as const;
export type FontWeightAlias = typeof fontWeightAlias[number];
36 changes: 22 additions & 14 deletions polaris-tokens/src/token-groups/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,26 @@ export const motion = {
export type MotionTokenGroup = TokenGroup<typeof motion>;
export type MotionTokenName = keyof MotionTokenGroup;

// e.g. "0" | "50" | "100" | "150" | ...
export type MotionDurationScale = Extract<
MotionTokenName,
`duration-${number}`
> extends `duration-${infer Scale}`
? Scale
: never;
export const motionDurationScale = [
'0',
'50',
'100',
'150',
'200',
'250',
'300',
'350',
'400',
'450',
'500',
'5000',
] as const;
export type MotionDurationScale = typeof motionDurationScale[number];

// e.g. "bounce" | "fade-in" | "pulse" | "spin"
export type MotionKeyframesAlias = Extract<
MotionTokenName,
`keyframes-${string}`
> extends `keyframes-${infer Alias}`
? Alias
: never;
export const motionKeyframesAlias = [
'bounce',
'fade-in',
'pulse',
'spin',
] as const;
export type MotionKeyframesAlias = typeof motionKeyframesAlias[number];
23 changes: 4 additions & 19 deletions polaris-tokens/src/token-groups/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,8 @@ export const shape = {
export type ShapeTokenGroup = TokenGroup<typeof shape>;
export type ShapeTokenName = keyof ShapeTokenGroup;

type ShapeBorderRadiusTokenName = Extract<
ShapeTokenName,
`border-radius-${string}`
>;
export const borderRadiusScale = ['05', '1', '2', '3', '4', '5', '6'] as const;
export type ShapeBorderRadiusScale = typeof borderRadiusScale[number];

// e.g. "05" | "1" | "2" | "3" | "4" | "5" | "6"
export type ShapeBorderRadiusScale = Extract<
ShapeBorderRadiusTokenName,
`border-radius-${number}`
> extends `border-radius-${infer Scale}`
? Scale
: never;

// e.g. "base" | "large" | "half"
export type ShapeBorderRadiusAlias = Exclude<
ShapeBorderRadiusTokenName,
`border-radius-${number}`
> extends `border-radius-${infer Alias}`
? Alias
: never;
export const borderRadiusAlias = ['base', 'large', 'half'] as const;
export type ShapeBorderRadiusAlias = typeof borderRadiusAlias[number];
27 changes: 20 additions & 7 deletions polaris-tokens/src/token-groups/spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,23 @@ export const spacing = {
export type SpacingTokenGroup = TokenGroup<typeof spacing>;
export type SpacingTokenName = keyof SpacingTokenGroup;

// e.g. "0" | "025" | "05" | "1" | "2" | "3" | ...
export type SpacingSpaceScale = Extract<
SpacingTokenName,
`space-${number}`
> extends `space-${infer Scale}`
? Scale
: never;
export const spaceScale = [
'0',
'025',
'05',
'1',
'2',
'3',
'4',
'5',
'6',
'8',
'10',
'12',
'16',
'20',
'24',
'28',
'32',
] as const;
export type SpacingSpaceScale = typeof spaceScale[number];
22 changes: 15 additions & 7 deletions polaris-tokens/src/token-groups/zIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ export const zIndex = {
export type ZIndexTokenGroup = TokenGroup<typeof zIndex>;
export type ZIndexTokenName = keyof ZIndexTokenGroup;

// e.g. "1" | "2" | "3" | "4" | "5" | "6" | ...
export type ZIndexZScale = Extract<
ZIndexTokenName,
`z-${number}`
> extends `z-${infer Scale}`
? Scale
: never;
export const zIndexZScale = [
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'10',
'12',
'9',
'11',
] as const;
export type ZIndexZScale = typeof zIndexZScale[number];
14 changes: 14 additions & 0 deletions polaris-tokens/tests/token-groups/breakpoints.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {isKeyOf} from '@shopify/polaris-migrator';

import {
breakpoints,
breakpointsAlias,
} from '../../src/token-groups/breakpoints';

describe('BreakpointsAlias', () => {
it('extracts the breakpoint alias from the breakpoints token', () => {
for (const alias of breakpointsAlias) {
expect(isKeyOf(breakpoints, `breakpoints-${alias}`)).toBe(true);
}
});
});
11 changes: 11 additions & 0 deletions polaris-tokens/tests/token-groups/depth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {isKeyOf} from '@shopify/polaris-migrator';

import {depth, depthShadowAlias} from '../../src/token-groups/depth';

describe('DepthShadowAlias', () => {
it('extracts the depth alias from the depth token', () => {
for (const alias of depthShadowAlias) {
expect(isKeyOf(depth, `shadow-${alias}`)).toBe(true);
}
});
});
32 changes: 32 additions & 0 deletions polaris-tokens/tests/token-groups/font.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {isKeyOf} from '@shopify/polaris-migrator';

import {
font,
fontSizeScale,
fontLineHeightScale,
fontWeightAlias,
} from '../../src/token-groups/font';

describe('FontSizeScale', () => {
it('extracts the font size scale from the font token', () => {
for (const sizeScale of fontSizeScale) {
expect(isKeyOf(font, `font-size-${sizeScale}`)).toBe(true);
}
});
});

describe('FontLineHeightScale', () => {
it('extracts the font line height scale from the font token', () => {
for (const lineHeightScale of fontLineHeightScale) {
expect(isKeyOf(font, `font-line-height-${lineHeightScale}`)).toBe(true);
}
});
});

describe('FontWeightAlias', () => {
it('extracts the font weight alias from the font token', () => {
for (const alias of fontWeightAlias) {
expect(isKeyOf(font, `font-weight-${alias}`)).toBe(true);
}
});
});
23 changes: 23 additions & 0 deletions polaris-tokens/tests/token-groups/motion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {isKeyOf} from '@shopify/polaris-migrator';

import {
motion,
motionDurationScale,
motionKeyframesAlias,
} from '../../src/token-groups/motion';

describe('MotionDurationScale', () => {
it('extracts the motion duration scale from the motion token', () => {
for (const scale of motionDurationScale) {
expect(isKeyOf(motion, `duration-${scale}`)).toBe(true);
}
});
});

describe('MotionKeyframesAlias', () => {
it('extracts the motion keyframe alias from the motion token', () => {
for (const alias of motionKeyframesAlias) {
expect(isKeyOf(motion, `keyframes-${alias}`)).toBe(true);
}
});
});
23 changes: 23 additions & 0 deletions polaris-tokens/tests/token-groups/shape.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {isKeyOf} from '@shopify/polaris-migrator';

import {
shape,
borderRadiusScale,
borderRadiusAlias,
} from '../../src/token-groups/shape';

describe('ShapeBorderRadiusScale', () => {
it('extracts the border radius scale from the shape token', () => {
for (const scale of borderRadiusScale) {
expect(isKeyOf(shape, `border-radius-${scale}`)).toBe(true);
}
});
});

describe('ShapeBorderRadiusAlias', () => {
it('extracts the border radius alias from the shape token', () => {
for (const alias of borderRadiusAlias) {
expect(isKeyOf(shape, `border-radius-${alias}`)).toBe(true);
}
});
});
11 changes: 11 additions & 0 deletions polaris-tokens/tests/token-groups/spacing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {isKeyOf} from '@shopify/polaris-migrator';

import {spacing, spaceScale} from '../../src/token-groups/spacing';

describe('SpacingSpaceScale', () => {
it('extracts the spacing scale from the spacing token', () => {
for (const scale of spaceScale) {
expect(isKeyOf(spacing, `space-${scale}`)).toBe(true);
}
});
});
11 changes: 11 additions & 0 deletions polaris-tokens/tests/token-groups/zIndex.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {isKeyOf} from '@shopify/polaris-migrator';

import {zIndex, zIndexZScale} from '../../src/token-groups/zIndex';

describe('ZIndexZScale', () => {
it('extracts the z-index scale from the zIndex token', () => {
for (const scale of zIndexZScale) {
expect(isKeyOf(zIndex, `z-${scale}`)).toBe(true);
}
});
});