Skip to content

Commit b2499f7

Browse files
authored
ref(ui2): improve space() deprecation notice (#95883)
Using TypeScript function overloads to provide better deprecation notices for the `space()` function
1 parent 5a197e8 commit b2499f7

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

static/app/styles/space.tsx

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,67 @@ const SPACES = {
1212
export type ValidSize = keyof typeof SPACES;
1313

1414
/**
15-
* @deprecated prefer using `theme.space`
15+
* @deprecated prefer `theme.space['2xs']`
16+
*/
17+
function space<S extends 0.25>(size: S): (typeof SPACES)[S];
18+
/**
19+
* @deprecated prefer `theme.space.xs`
20+
*/
21+
function space<S extends 0.5>(size: S): (typeof SPACES)[S];
22+
/**
23+
* @deprecated prefer `theme.space.sm`
24+
*/
25+
function space<S extends 0.75>(size: S): (typeof SPACES)[S];
26+
/**
27+
* @deprecated prefer `theme.space.md`
28+
*/
29+
function space<S extends 1>(size: S): (typeof SPACES)[S];
30+
/**
31+
* @deprecated prefer `theme.space.lg`
32+
*/
33+
function space<S extends 1.5>(size: S): (typeof SPACES)[S];
34+
/**
35+
* @deprecated prefer `theme.space.xl`
36+
*/
37+
function space<S extends 2>(size: S): (typeof SPACES)[S];
38+
/**
39+
* @deprecated prefer `theme.space['2xl']`
40+
*/
41+
function space<S extends 3>(size: S): (typeof SPACES)[S];
42+
/**
43+
* @deprecated prefer `theme.space['3xl']`
44+
*/
45+
function space<S extends 4>(size: S): (typeof SPACES)[S];
46+
/**
47+
* @deprecated replace with `theme.space.*` value from the
48+
*
49+
*
50+
* | before | after | value |
51+
* | ------ | ------ | -------------------- |
52+
* | | `none` | `0px` (new!) |
53+
* | `0.25` | `2xs` | `2px` |
54+
* | `0.5` | `xs` | `4px` |
55+
* | `0.75` | `sm` | `6px` |
56+
* | `1` | `md` | `8px` |
57+
* | `1.5` | `lg` | `12px` |
58+
* | `2` | `xl` | `16px` |
59+
* | `3` | `2xl` | `24px` (from `20px`) |
60+
* | `4` | `3xl` | `32px` (from `30px`) |
61+
*/
62+
function space<S extends ValidSize>(size: S): (typeof SPACES)[S];
63+
/**
64+
* @deprecated replace with `theme.space.*`
65+
* | before | after | value |
66+
* | ------ | ------ | -------------------- |
67+
* | | `none` | `0px` (new!) |
68+
* | `0.25` | `2xs` | `2px` |
69+
* | `0.5` | `xs` | `4px` |
70+
* | `0.75` | `sm` | `6px` |
71+
* | `1` | `md` | `8px` |
72+
* | `1.5` | `lg` | `12px` |
73+
* | `2` | `xl` | `16px` |
74+
* | `3` | `2xl` | `24px` (from `20px`) |
75+
* | `4` | `3xl` | `32px` (from `30px`) |
1676
*/
1777
function space<S extends ValidSize>(size: S): (typeof SPACES)[S] {
1878
return SPACES[size];

0 commit comments

Comments
 (0)