@codeleap/styles 6.3.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/Cacher.d.ts +87 -0
- package/dist/classes/Cacher.d.ts.map +1 -0
- package/dist/classes/StaleControl.d.ts +65 -0
- package/dist/classes/StaleControl.d.ts.map +1 -0
- package/dist/classes/StyleCache.d.ts +63 -0
- package/dist/classes/StyleCache.d.ts.map +1 -0
- package/dist/classes/StylePersistor.d.ts +52 -0
- package/dist/classes/StylePersistor.d.ts.map +1 -0
- package/dist/classes/StyleRegistry.d.ts +108 -0
- package/dist/classes/StyleRegistry.d.ts.map +1 -0
- package/dist/classes/index.d.ts +3 -0
- package/dist/classes/index.d.ts.map +1 -0
- package/dist/constants.d.ts +22 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useCompositionStyles.d.ts +12 -0
- package/dist/hooks/useCompositionStyles.d.ts.map +1 -0
- package/dist/hooks/useNestedStylesByKey.d.ts +11 -0
- package/dist/hooks/useNestedStylesByKey.d.ts.map +1 -0
- package/dist/hooks/useStyleObserver.d.ts +9 -0
- package/dist/hooks/useStyleObserver.d.ts.map +1 -0
- package/dist/hooks/useTheme.d.ts +19 -0
- package/dist/hooks/useTheme.d.ts.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/calc.d.ts +27 -0
- package/dist/lib/calc.d.ts.map +1 -0
- package/dist/lib/createStyles.d.ts +30 -0
- package/dist/lib/createStyles.d.ts.map +1 -0
- package/dist/lib/createTheme.d.ts +28 -0
- package/dist/lib/createTheme.d.ts.map +1 -0
- package/dist/lib/cssVariables.d.ts +35 -0
- package/dist/lib/cssVariables.d.ts.map +1 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/theme/generateColorScheme.d.ts +22 -0
- package/dist/theme/generateColorScheme.d.ts.map +1 -0
- package/dist/theme/index.d.ts +4 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/themeStore.d.ts +106 -0
- package/dist/theme/themeStore.d.ts.map +1 -0
- package/dist/theme/validateTheme.d.ts +19 -0
- package/dist/theme/validateTheme.d.ts.map +1 -0
- package/dist/tools/colors.d.ts +70 -0
- package/dist/tools/colors.d.ts.map +1 -0
- package/dist/tools/deepClone.d.ts +7 -0
- package/dist/tools/deepClone.d.ts.map +1 -0
- package/dist/tools/deepmerge.d.ts +13 -0
- package/dist/tools/deepmerge.d.ts.map +1 -0
- package/dist/tools/hashKey.d.ts +8 -0
- package/dist/tools/hashKey.d.ts.map +1 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/minifier.d.ts +24 -0
- package/dist/tools/minifier.d.ts.map +1 -0
- package/dist/tools/multiplierProperty.d.ts +4 -0
- package/dist/tools/multiplierProperty.d.ts.map +1 -0
- package/dist/types/cache.d.ts +12 -0
- package/dist/types/cache.d.ts.map +1 -0
- package/dist/types/component.d.ts +58 -0
- package/dist/types/component.d.ts.map +1 -0
- package/dist/types/core.d.ts +77 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/icon.d.ts +15 -0
- package/dist/types/icon.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/spacing.d.ts +28 -0
- package/dist/types/spacing.d.ts.map +1 -0
- package/dist/types/store.d.ts +12 -0
- package/dist/types/store.d.ts.map +1 -0
- package/dist/types/style.d.ts +42 -0
- package/dist/types/style.d.ts.map +1 -0
- package/dist/types/theme.d.ts +109 -0
- package/dist/types/theme.d.ts.map +1 -0
- package/dist/utils.d.ts +40 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/variants/borderCreator.d.ts +22 -0
- package/dist/variants/borderCreator.d.ts.map +1 -0
- package/dist/variants/createAppVariants.d.ts +18 -0
- package/dist/variants/createAppVariants.d.ts.map +1 -0
- package/dist/variants/defaultVariants.d.ts +140 -0
- package/dist/variants/defaultVariants.d.ts.map +1 -0
- package/dist/variants/dynamicVariants.d.ts +43 -0
- package/dist/variants/dynamicVariants.d.ts.map +1 -0
- package/dist/variants/index.d.ts +7 -0
- package/dist/variants/index.d.ts.map +1 -0
- package/dist/variants/mediaQuery.d.ts +30 -0
- package/dist/variants/mediaQuery.d.ts.map +1 -0
- package/dist/variants/spacing.d.ts +26 -0
- package/dist/variants/spacing.d.ts.map +1 -0
- package/package.json +19 -5
- package/src/classes/Cacher.ts +9 -9
- package/src/classes/StaleControl.ts +1 -1
- package/src/classes/StyleCache.ts +9 -3
- package/src/classes/StylePersistor.ts +11 -0
- package/src/classes/StyleRegistry.ts +124 -43
- package/src/classes/tests/StyleRegistry.spec.ts +169 -0
- package/src/constants.ts +14 -0
- package/src/hooks/useCompositionStyles.ts +9 -7
- package/src/hooks/useNestedStylesByKey.ts +8 -0
- package/src/hooks/useStyleObserver.ts +6 -5
- package/src/hooks/useTheme.ts +14 -0
- package/src/lib/calc.ts +13 -0
- package/src/lib/createStyles.ts +35 -4
- package/src/lib/createTheme.ts +74 -25
- package/src/lib/cssVariables.ts +74 -0
- package/src/lib/index.ts +2 -1
- package/src/lib/tests/createStyles.spec.ts +80 -23
- package/src/lib/tests/createStylesWithContext.spec.ts +108 -0
- package/src/tests/theme.ts +6 -2
- package/src/theme/generateColorScheme.ts +13 -10
- package/src/theme/tests/themeStore.spec.ts +38 -37
- package/src/theme/themeStore.ts +10 -7
- package/src/theme/validateTheme.ts +1 -1
- package/src/tools/colors.ts +24 -36
- package/src/tools/deepClone.ts +3 -5
- package/src/tools/deepmerge.ts +8 -6
- package/src/tools/hashKey.ts +4 -5
- package/src/tools/minifier.ts +11 -12
- package/src/tools/tests/deepClone.spec.ts +2 -2
- package/src/types/cache.ts +10 -0
- package/src/types/component.ts +41 -5
- package/src/types/core.ts +66 -6
- package/src/types/icon.ts +11 -0
- package/src/types/spacing.ts +21 -0
- package/src/types/store.ts +6 -0
- package/src/types/style.ts +37 -10
- package/src/types/theme.ts +37 -1
- package/src/utils.ts +34 -4
- package/src/variants/borderCreator.ts +14 -5
- package/src/variants/createAppVariants.ts +11 -0
- package/src/variants/defaultVariants.ts +28 -8
- package/src/variants/dynamicVariants.ts +76 -18
- package/src/variants/mediaQuery.ts +18 -0
- package/src/variants/spacing.ts +15 -1
- package/package.json.bak +0 -30
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { ICSS } from '../types'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Static built-in style variants available to every component without any registration.
|
|
5
|
+
* These are merged as the lowest-priority layer in `commonVariants`, so app-defined
|
|
6
|
+
* variants and dynamic variants can override them.
|
|
7
|
+
*
|
|
8
|
+
* Notable entries:
|
|
9
|
+
* - `grow` — sets `flex: 1` (not `display: flex`; use `row`/`column` for flex containers).
|
|
10
|
+
* - `inset` — shorthand for `{ top:0, bottom:0, left:0, right:0 }` (useful with `absolute`).
|
|
11
|
+
* - `insetX` / `insetY` — pin to horizontal or vertical edges only.
|
|
12
|
+
* - `centerChildren` — centers children via `alignItems`/`justifyContent`; requires a flex container.
|
|
13
|
+
* - `'visibility:hidden'` / `'display:none'` — use quoted keys in style arrays.
|
|
14
|
+
*/
|
|
3
15
|
export const defaultVariants = {
|
|
4
16
|
block: {
|
|
5
17
|
display: 'block',
|
|
6
18
|
},
|
|
7
|
-
|
|
8
|
-
display: 'flex',
|
|
19
|
+
grow: {
|
|
9
20
|
flex: 1,
|
|
10
21
|
},
|
|
11
22
|
absolute: {
|
|
@@ -28,9 +39,7 @@ export const defaultVariants = {
|
|
|
28
39
|
top: 0,
|
|
29
40
|
bottom: 0,
|
|
30
41
|
},
|
|
31
|
-
|
|
32
|
-
display: 'none',
|
|
33
|
-
},
|
|
42
|
+
|
|
34
43
|
full: {
|
|
35
44
|
width: '100%',
|
|
36
45
|
height: '100%',
|
|
@@ -44,7 +53,7 @@ export const defaultVariants = {
|
|
|
44
53
|
fullHeight: {
|
|
45
54
|
height: '100%',
|
|
46
55
|
},
|
|
47
|
-
|
|
56
|
+
inset: {
|
|
48
57
|
top: 0,
|
|
49
58
|
bottom: 0,
|
|
50
59
|
left: 0,
|
|
@@ -60,9 +69,10 @@ export const defaultVariants = {
|
|
|
60
69
|
flexDirection: 'row',
|
|
61
70
|
},
|
|
62
71
|
column: {
|
|
72
|
+
display: 'flex',
|
|
63
73
|
flexDirection: 'column',
|
|
64
74
|
},
|
|
65
|
-
|
|
75
|
+
centerChildren: {
|
|
66
76
|
alignItems: 'center',
|
|
67
77
|
justifyContent: 'center',
|
|
68
78
|
},
|
|
@@ -114,9 +124,19 @@ export const defaultVariants = {
|
|
|
114
124
|
textCenter: {
|
|
115
125
|
textAlign: 'center',
|
|
116
126
|
},
|
|
117
|
-
|
|
127
|
+
flexWrap: {
|
|
118
128
|
flexWrap: 'wrap',
|
|
119
129
|
},
|
|
130
|
+
'visibility:hidden': {
|
|
131
|
+
visibility: 'hidden'
|
|
132
|
+
},
|
|
133
|
+
'visibility:visible': {
|
|
134
|
+
visibility: 'visible'
|
|
135
|
+
},
|
|
136
|
+
'display:none': {
|
|
137
|
+
display:'none'
|
|
138
|
+
}
|
|
120
139
|
} as const
|
|
121
140
|
|
|
141
|
+
/** Typed record mapping every built-in variant name to an `ICSS` value. */
|
|
122
142
|
export type DefaultVariants = Record<keyof typeof defaultVariants, ICSS>
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import { IBorderRadius, IColors, IEffects } from '../types'
|
|
1
|
+
import { IBorderRadius, IColors, IEffects, ISizes, ITheme } from '../types'
|
|
2
2
|
import { capitalize } from '../utils'
|
|
3
3
|
|
|
4
|
+
/** Callback shape for a variant that receives a raw value and returns a style fragment. */
|
|
4
5
|
export type VariantFunction = (value: any) => any
|
|
5
6
|
|
|
7
|
+
/** CSS properties that accept a color token: `backgroundColor` and `color`. */
|
|
6
8
|
export const colorVariants = ['backgroundColor', 'color'] as const
|
|
7
9
|
|
|
10
|
+
/** Horizontal border directions used when generating per-corner radius variants. */
|
|
8
11
|
export const borderXDirection = ['left', 'right'] as const
|
|
12
|
+
/** Vertical border directions used when generating per-corner radius variants. */
|
|
9
13
|
export const borderYDirection = ['bottom', 'top'] as const
|
|
14
|
+
/** All four border directions plus the un-suffixed (all-sides) form. */
|
|
10
15
|
export const borderDirection = [...borderYDirection, ...borderXDirection, ''] as const
|
|
16
|
+
/** Border sub-properties generated for each direction. */
|
|
11
17
|
export const borderProperties = ['color', 'radius', 'width'] as const
|
|
12
18
|
|
|
19
|
+
/** CSS cursor values surfaced as `cursor:<value>` style variants. */
|
|
13
20
|
export const cursorTypes = [
|
|
14
21
|
'not-allowed',
|
|
15
22
|
'help',
|
|
@@ -18,35 +25,58 @@ export const cursorTypes = [
|
|
|
18
25
|
'',
|
|
19
26
|
] as const
|
|
20
27
|
|
|
28
|
+
/** Numeric value or the empty-string terminator used in `scale:` variant templates. */
|
|
21
29
|
export type Value =
|
|
22
30
|
| number
|
|
23
31
|
| ''
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
type MatchKeysByValue<
|
|
34
|
+
T extends Record<string, any>,
|
|
35
|
+
Values
|
|
36
|
+
> = { [K in keyof T]: T[K] extends Values ? K : never }[keyof T]
|
|
29
37
|
|
|
38
|
+
// @note
|
|
39
|
+
// Adding the baseColors here make it extremely heavy,
|
|
40
|
+
// perhaps in a future typescript update it will be better. We exclude any non-string keys because those are namespaces (usually components)
|
|
41
|
+
type Color = MatchKeysByValue<IColors, string>// keyof IColors
|
|
42
|
+
|
|
43
|
+
type Sizes = keyof ISizes
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Union of all parametric variant strings resolved at runtime by looking up the
|
|
47
|
+
* provided value in the theme. Examples: `"color:primary"`, `"bg:neutral"`,
|
|
48
|
+
* `"borderRadius:sm"`, `"cursor:pointer"`, `"scale:0.95"`, `"size:icon"`.
|
|
49
|
+
* The part before `:` is the variant name; the part after is the token key or raw value.
|
|
50
|
+
*/
|
|
30
51
|
export type DynamicVariants =
|
|
31
52
|
`color:${Color}` |
|
|
32
53
|
`border${Capitalize<typeof borderDirection[number]>}Width:${keyof IBorderRadius}` |
|
|
33
54
|
`border${Capitalize<typeof borderDirection[number]>}Color:${Color}` |
|
|
34
55
|
`borderRadius:${keyof IBorderRadius}` |
|
|
35
56
|
`border${Capitalize<typeof borderYDirection[number]>}${Capitalize<typeof borderXDirection[number]>}Radius:${keyof IBorderRadius}` |
|
|
57
|
+
`border${Capitalize<typeof borderYDirection[number]>}Radius:${keyof IBorderRadius}` |
|
|
58
|
+
`border${Capitalize<typeof borderXDirection[number]>}Radius:${keyof IBorderRadius}` |
|
|
36
59
|
`cursor:${typeof cursorTypes[number]}` |
|
|
37
60
|
`bg:${Color}` |
|
|
38
61
|
`br:${keyof IBorderRadius}` |
|
|
39
|
-
`scale:${Value}`
|
|
40
|
-
|
|
62
|
+
`scale:${Value}` |
|
|
63
|
+
`size:${Sizes}`
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Builds the dynamic variant registry object at module initialisation time.
|
|
67
|
+
* Each entry is a function `(theme, value) => ICSS` keyed by the variant name
|
|
68
|
+
* (the part before `:` in the variant string). The registry is consumed by
|
|
69
|
+
* `CodeleapStyleRegistry.computeCommonVariantStyle`.
|
|
70
|
+
*/
|
|
41
71
|
export const createDynamicVariants = () => {
|
|
42
|
-
const dynamicVariants = {}
|
|
72
|
+
const dynamicVariants: Record<string, any> = {}
|
|
43
73
|
|
|
44
74
|
function createVariant(variantName: string, variantReturn: any) {
|
|
45
75
|
dynamicVariants[variantName] = variantReturn
|
|
46
76
|
}
|
|
47
77
|
|
|
48
78
|
colorVariants.forEach(variant => {
|
|
49
|
-
createVariant(variant, (theme, color: Color) => ({
|
|
79
|
+
createVariant(variant, (theme: ITheme & Record<string, any>, color: Color) => ({
|
|
50
80
|
[variant]: theme.colors[color],
|
|
51
81
|
}))
|
|
52
82
|
})
|
|
@@ -56,42 +86,70 @@ export const createDynamicVariants = () => {
|
|
|
56
86
|
borderXDirection.forEach(y => {
|
|
57
87
|
const variant = `border${capitalize(direction)}${capitalize(y)}Radius`
|
|
58
88
|
|
|
59
|
-
createVariant(variant, (theme, value: keyof IBorderRadius) => ({
|
|
89
|
+
createVariant(variant, (theme: ITheme & Record<string, any>, value: keyof IBorderRadius) => ({
|
|
60
90
|
[variant]: theme.radius[value],
|
|
61
91
|
}))
|
|
62
92
|
})
|
|
63
93
|
}
|
|
64
94
|
|
|
95
|
+
|
|
96
|
+
|
|
65
97
|
borderProperties.forEach(property => {
|
|
66
98
|
const variant = `border${capitalize(direction)}${capitalize(property)}`
|
|
67
99
|
|
|
68
|
-
createVariant(variant, (theme, value: string) => ({
|
|
69
|
-
[variant]: property == 'color' ? theme.colors[value] : theme.radius[value],
|
|
100
|
+
createVariant(variant, (theme: ITheme & Record<string, any>, value: string) => ({
|
|
101
|
+
[variant]: property == 'color' ? (theme.colors as Record<string, any>)[value] : (theme.radius as Record<string, any>)[value],
|
|
70
102
|
}))
|
|
71
103
|
})
|
|
72
104
|
})
|
|
73
105
|
|
|
74
|
-
|
|
106
|
+
borderXDirection.forEach(x => {
|
|
107
|
+
const variant = `border${capitalize(x)}Radius`
|
|
108
|
+
|
|
109
|
+
createVariant(variant, (theme: ITheme & Record<string, any>, value: keyof IBorderRadius) => ({
|
|
110
|
+
[variant]: theme.radius[value],
|
|
111
|
+
}))
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
borderYDirection.forEach(y => {
|
|
115
|
+
const variant = `border${capitalize(y)}Radius`
|
|
116
|
+
|
|
117
|
+
createVariant(variant, (theme: ITheme & Record<string, any>, value: keyof IBorderRadius) => ({
|
|
118
|
+
[variant]: theme.radius[value],
|
|
119
|
+
}))
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
createVariant('cursor', (theme: ITheme & Record<string, any>, cursor: typeof cursorTypes[number]) => ({ cursor }))
|
|
75
124
|
|
|
76
|
-
createVariant('bg', (theme, color: Color) => ({
|
|
125
|
+
createVariant('bg', (theme: ITheme & Record<string, any>, color: Color) => ({
|
|
77
126
|
backgroundColor: theme.colors[color],
|
|
78
127
|
}))
|
|
79
128
|
|
|
80
|
-
createVariant('effect', (theme, effect: keyof IEffects) => theme.effects[effect])
|
|
129
|
+
createVariant('effect', (theme: ITheme & Record<string, any>, effect: keyof IEffects) => theme.effects[effect])
|
|
81
130
|
|
|
82
|
-
createVariant('scale', (theme, value: any) => ({
|
|
131
|
+
createVariant('scale', (theme: ITheme & Record<string, any>, value: any) => ({
|
|
83
132
|
transform: theme.isBrowser ? `scale(${value})` : [{ 'scale': Number(value) }],
|
|
84
133
|
}))
|
|
85
134
|
|
|
86
|
-
createVariant('br', (theme, value: keyof IBorderRadius) => ({
|
|
135
|
+
createVariant('br', (theme: ITheme & Record<string, any>, value: keyof IBorderRadius) => ({
|
|
87
136
|
borderRadius: theme.radius[value],
|
|
88
137
|
}))
|
|
89
138
|
|
|
90
|
-
createVariant('borderRadius', (theme, value: keyof IBorderRadius) => ({
|
|
139
|
+
createVariant('borderRadius', (theme: ITheme & Record<string, any>, value: keyof IBorderRadius) => ({
|
|
91
140
|
borderRadius: theme.radius[value],
|
|
92
141
|
}))
|
|
93
142
|
|
|
143
|
+
createVariant('size', (theme: ITheme & Record<string, any>, value: keyof ISizes) => ({
|
|
144
|
+
height: theme.size[value],
|
|
145
|
+
width: theme.size[value],
|
|
146
|
+
}))
|
|
147
|
+
|
|
94
148
|
return dynamicVariants
|
|
95
149
|
}
|
|
96
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Pre-built dynamic variant registry used by the `CodeleapStyleRegistry`.
|
|
153
|
+
* Created once at module load; re-creation would lose the closed-over variant map.
|
|
154
|
+
*/
|
|
97
155
|
export const dynamicVariants = createDynamicVariants()
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { Breakpoint } from '../types'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* The four directional media-query helpers. Each returns a complete `@media` string
|
|
5
|
+
* that can be used as a nested style key.
|
|
6
|
+
* - `up` — `min-width` (at and above the breakpoint).
|
|
7
|
+
* - `down` — `max-width` (at and below the breakpoint).
|
|
8
|
+
* - `is` — exact match (`min-width` AND `max-width` at the same value).
|
|
9
|
+
* - `not` — negated exact match.
|
|
10
|
+
*/
|
|
3
11
|
export type Queries = {
|
|
4
12
|
up: (breakpoint: string) => string
|
|
5
13
|
down: (breakpoint: Breakpoint) => string
|
|
@@ -7,6 +15,11 @@ export type Queries = {
|
|
|
7
15
|
not: (breakpoint: string) => string
|
|
8
16
|
}
|
|
9
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Extends `Queries` with `renderToPlatformQuery`, which inverts the query direction
|
|
20
|
+
* for React Native's platform-query rendering: `up` becomes `down`, `is` becomes `not`,
|
|
21
|
+
* etc. This is how responsive styles declared for web are translated to RN media conditions.
|
|
22
|
+
*/
|
|
10
23
|
export type MediaQueries = Queries & {
|
|
11
24
|
renderToPlatformQuery: (props: Record<keyof Queries, any>) => string
|
|
12
25
|
}
|
|
@@ -19,6 +32,11 @@ function getBreakpointValue(breakpoint: any, breakpoints: any) {
|
|
|
19
32
|
return Infinity
|
|
20
33
|
}
|
|
21
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Produces a `MediaQueries` object bound to the provided `breakpoints` map.
|
|
37
|
+
* Unknown breakpoints (not in the map) fall back to `Infinity`, making `up(unknown)`
|
|
38
|
+
* match all widths and `down(unknown)` match none.
|
|
39
|
+
*/
|
|
22
40
|
export function createMediaQueries<T extends any>(breakpoints: T): MediaQueries {
|
|
23
41
|
function getBreakpoint(breakpoint: any) {
|
|
24
42
|
return getBreakpointValue(breakpoint, breakpoints)
|
package/src/variants/spacing.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { ICSS } from '../types'
|
|
2
2
|
import { spacingVariants, spacingShortVariants, SpacingVariants, SpacingShortVariants } from '../types/spacing'
|
|
3
3
|
|
|
4
|
+
/** Function returned by a spacing factory entry; accepts a multiplier and returns a style fragment. */
|
|
4
5
|
export type MultiplierFunction = (multiplier: number | string) => ICSS
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Typed shape of the spacing object produced by `spacingFactory` for a given property.
|
|
9
|
+
* When `S` is `boolean`, the direction variants are long-form (`SpacingVariants`);
|
|
10
|
+
* when `S` is `string`, they are short-form (`SpacingShortVariants`).
|
|
11
|
+
*/
|
|
6
12
|
export type Spacings<T extends string, S = boolean> = {
|
|
7
13
|
[Property in (S extends boolean ? SpacingVariants : SpacingShortVariants) as `${T}${string & Property}`]: MultiplierFunction;
|
|
8
14
|
} & {
|
|
@@ -31,6 +37,14 @@ const shortPositionMap = {
|
|
|
31
37
|
'b': 'Bottom'
|
|
32
38
|
}
|
|
33
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Builds a spacing variant map for a CSS property (`'padding'`, `'margin'`, `'p'`, `'m'`).
|
|
42
|
+
* Each key in the returned object is a callable that multiplies its argument by `base`.
|
|
43
|
+
* Passing `isShort = true` uses single-letter direction suffixes and maps them to their
|
|
44
|
+
* long-form equivalents before producing the CSS property name.
|
|
45
|
+
* The `'Horizontal'` and `'Vertical'` (or `'x'`/`'y'`) directions expand to two
|
|
46
|
+
* properties each; the empty-string direction produces all four sides at once.
|
|
47
|
+
*/
|
|
34
48
|
export function spacingFactory<T extends string>(
|
|
35
49
|
base: number,
|
|
36
50
|
spacingProperty: T,
|
|
@@ -39,7 +53,7 @@ export function spacingFactory<T extends string>(
|
|
|
39
53
|
const baseProperty = isShort ? shortMapValues[spacingProperty as keyof typeof shortMapValues] : spacingProperty
|
|
40
54
|
const positions = isShort ? spacingShortVariants : spacingVariants
|
|
41
55
|
|
|
42
|
-
const spacings = {
|
|
56
|
+
const spacings: Record<string, (n: number | string) => Record<string, any>> = {
|
|
43
57
|
[`${spacingProperty}`]: (n: number | string) => {
|
|
44
58
|
if (n === 'auto') {
|
|
45
59
|
return { [baseProperty]: 'auto' }
|
package/package.json.bak
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@codeleap/styles",
|
|
3
|
-
"version": "6.3.0",
|
|
4
|
-
"main": "src/index.ts",
|
|
5
|
-
"license": "UNLICENSED",
|
|
6
|
-
"repository": {
|
|
7
|
-
"url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
|
|
8
|
-
"type": "git",
|
|
9
|
-
"directory": "packages/styles"
|
|
10
|
-
},
|
|
11
|
-
"devDependencies": {
|
|
12
|
-
"@codeleap/config": "workspace:*",
|
|
13
|
-
"ts-node-dev": "^1.1.8"
|
|
14
|
-
},
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "echo 'No build needed'"
|
|
17
|
-
},
|
|
18
|
-
"peerDependencies": {
|
|
19
|
-
"react": "19.1.0",
|
|
20
|
-
"typescript": "5.5.2"
|
|
21
|
-
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@fastify/deepmerge": "3.1.0",
|
|
24
|
-
"@nanostores/react": "1.0.0",
|
|
25
|
-
"js-sha256": "0.11.1",
|
|
26
|
-
"lz-string": "1.5.0",
|
|
27
|
-
"nanostores": "1.0.1",
|
|
28
|
-
"rfdc": "1.4.1"
|
|
29
|
-
}
|
|
30
|
-
}
|