@codecademy/variance 0.25.3-alpha.e71051.0 → 0.25.3-alpha.f73629.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/core.js +5 -22
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -2
- package/dist/types/config.d.ts +4 -8
- package/dist/types/properties.d.ts +0 -9
- package/dist/utils/propNames.js +7 -15
- package/package.json +2 -2
- package/dist/getPropertyMode/getPropertyMode.d.ts +0 -2
- package/dist/getPropertyMode/getPropertyMode.js +0 -3
- package/dist/getPropertyMode/getPropertyMode.test.js +0 -15
- package/dist/getPropertyMode/index.d.ts +0 -1
- package/dist/getPropertyMode/index.js +0 -1
package/dist/core.js
CHANGED
|
@@ -62,13 +62,11 @@ export const variance = {
|
|
|
62
62
|
const {
|
|
63
63
|
transform = identity,
|
|
64
64
|
property,
|
|
65
|
-
properties
|
|
66
|
-
scale
|
|
67
|
-
resolveProperty
|
|
65
|
+
properties = [property],
|
|
66
|
+
scale
|
|
68
67
|
} = config;
|
|
69
68
|
const getScaleValue = createScaleLookup(scale);
|
|
70
69
|
const alwaysTransform = scale === undefined || isArray(scale);
|
|
71
|
-
const isDirectionalProperties = props => props !== undefined && !isArray(props) && 'physical' in props && 'logical' in props;
|
|
72
70
|
return {
|
|
73
71
|
...config,
|
|
74
72
|
prop,
|
|
@@ -95,33 +93,18 @@ export const variance = {
|
|
|
95
93
|
default:
|
|
96
94
|
return styles;
|
|
97
95
|
}
|
|
98
|
-
const useLogicalProperties = props.theme?.useLogicalProperties ?? true;
|
|
99
|
-
let resolvedProperties;
|
|
100
|
-
if (isDirectionalProperties(configProperties)) {
|
|
101
|
-
const mode = resolveProperty ? resolveProperty(useLogicalProperties) : useLogicalProperties ? 'logical' : 'physical';
|
|
102
|
-
resolvedProperties = configProperties[mode];
|
|
103
|
-
} else {
|
|
104
|
-
resolvedProperties = configProperties ?? [property];
|
|
105
|
-
}
|
|
106
96
|
|
|
107
97
|
// for each property look up the scale value from theme if passed and apply any
|
|
108
98
|
// final transforms to the value
|
|
109
|
-
|
|
110
|
-
let resolvedProperty;
|
|
111
|
-
if (resolveProperty && typeof property === 'object') {
|
|
112
|
-
const mode = resolveProperty(useLogicalProperties);
|
|
113
|
-
resolvedProperty = property[mode];
|
|
114
|
-
} else {
|
|
115
|
-
resolvedProperty = property;
|
|
116
|
-
}
|
|
99
|
+
properties.forEach(property => {
|
|
117
100
|
let styleValue = intermediateValue;
|
|
118
101
|
if (useTransform && !isUndefined(styleValue)) {
|
|
119
|
-
styleValue = transform(styleValue,
|
|
102
|
+
styleValue = transform(styleValue, property, props);
|
|
120
103
|
}
|
|
121
104
|
switch (typeof styleValue) {
|
|
122
105
|
case 'number':
|
|
123
106
|
case 'string':
|
|
124
|
-
return styles[
|
|
107
|
+
return styles[property] = styleValue;
|
|
125
108
|
case 'object':
|
|
126
109
|
return Object.assign(styles, styleValue);
|
|
127
110
|
default:
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types/config.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { Theme } from '@emotion/react';
|
|
2
|
-
import { DefaultCSSPropertyValue,
|
|
2
|
+
import { DefaultCSSPropertyValue, PropertyTypes } from './properties';
|
|
3
3
|
import { AbstractProps, CSSObject, CSSPropMap, CSSProps, ResponsiveProp, ThemeProps } from './props';
|
|
4
4
|
import { AllUnionKeys, Key, KeyFromUnion } from './utils';
|
|
5
5
|
export type MapScale = Record<string | number, string | number>;
|
|
6
6
|
export type ArrayScale = readonly (string | number)[] & {
|
|
7
7
|
length: 0;
|
|
8
8
|
};
|
|
9
|
-
export type PropertyValue = keyof PropertyTypes | DirectionalProperty;
|
|
10
9
|
export interface BaseProperty {
|
|
11
|
-
property:
|
|
12
|
-
properties?: readonly
|
|
10
|
+
property: keyof PropertyTypes;
|
|
11
|
+
properties?: readonly (keyof PropertyTypes)[];
|
|
13
12
|
}
|
|
14
13
|
export interface Prop extends BaseProperty {
|
|
15
14
|
scale?: keyof Theme | MapScale | ArrayScale;
|
|
16
15
|
transform?: (val: string | number, prop?: string, props?: AbstractProps) => string | number | CSSObject;
|
|
17
|
-
resolveProperty?: (useLogicalProperties: boolean) => PropertyMode;
|
|
18
16
|
}
|
|
19
17
|
export interface AbstractPropTransformer extends Prop {
|
|
20
18
|
prop: string;
|
|
@@ -26,8 +24,7 @@ export interface AbstractParser {
|
|
|
26
24
|
config: Record<string, AbstractPropTransformer>;
|
|
27
25
|
}
|
|
28
26
|
export type PropertyValues<Property extends keyof PropertyTypes, All extends boolean = false> = Exclude<PropertyTypes<All extends true ? DefaultCSSPropertyValue : never>[Property], All extends true ? never : object | any[]>;
|
|
29
|
-
type
|
|
30
|
-
export type ScaleValue<Config extends Prop> = Config['scale'] extends keyof Theme ? keyof Theme[Config['scale']] | PropertyValues<BasePropertyKey<Config['property']>> : Config['scale'] extends MapScale ? keyof Config['scale'] | PropertyValues<BasePropertyKey<Config['property']>> : Config['scale'] extends ArrayScale ? Config['scale'][number] | PropertyValues<BasePropertyKey<Config['property']>> : PropertyValues<BasePropertyKey<Config['property']>, true>;
|
|
27
|
+
export type ScaleValue<Config extends Prop> = Config['scale'] extends keyof Theme ? keyof Theme[Config['scale']] | PropertyValues<Config['property']> : Config['scale'] extends MapScale ? keyof Config['scale'] | PropertyValues<Config['property']> : Config['scale'] extends ArrayScale ? Config['scale'][number] | PropertyValues<Config['property']> : PropertyValues<Config['property'], true>;
|
|
31
28
|
export type Scale<Config extends Prop> = ResponsiveProp<ScaleValue<Config> | ((theme: Theme) => ScaleValue<Config>)>;
|
|
32
29
|
export interface TransformFn<P extends string, Config extends Prop> {
|
|
33
30
|
(value: Scale<Config> | Scale<Config>, prop: P, props: ThemeProps<{
|
|
@@ -72,4 +69,3 @@ export type SystemProps<P extends AbstractParser> = {
|
|
|
72
69
|
export type VariantProps<T extends string, V> = {
|
|
73
70
|
[Key in T]?: V;
|
|
74
71
|
};
|
|
75
|
-
export {};
|
|
@@ -19,13 +19,4 @@ export interface VendorPropertyTypes<Overrides = DefaultCSSPropertyValue> extend
|
|
|
19
19
|
}
|
|
20
20
|
export interface CSSPropertyTypes<Overrides = DefaultCSSPropertyValue> extends PropertyTypes<Overrides>, VendorPropertyTypes<Overrides> {
|
|
21
21
|
}
|
|
22
|
-
export type PropertyMode = 'logical' | 'physical';
|
|
23
|
-
export interface DirectionalProperty {
|
|
24
|
-
physical: keyof PropertyTypes;
|
|
25
|
-
logical: keyof PropertyTypes;
|
|
26
|
-
}
|
|
27
|
-
export interface DirectionalProperties {
|
|
28
|
-
physical: readonly (keyof PropertyTypes)[];
|
|
29
|
-
logical: readonly (keyof PropertyTypes)[];
|
|
30
|
-
}
|
|
31
22
|
export {};
|
package/dist/utils/propNames.js
CHANGED
|
@@ -9,14 +9,6 @@ const compare = (a, b) => {
|
|
|
9
9
|
if (b < a) return SORT.B_BEFORE_A;
|
|
10
10
|
return SORT.EQUAL;
|
|
11
11
|
};
|
|
12
|
-
const isShorthand = prop => typeof prop === 'string' && SHORTHAND_PROPERTIES.includes(prop);
|
|
13
|
-
const getShorthandIndex = prop => typeof prop === 'string' ? SHORTHAND_PROPERTIES.indexOf(prop) : -1;
|
|
14
|
-
const getPropertiesCount = properties => {
|
|
15
|
-
if (!properties) return 0;
|
|
16
|
-
if (Array.isArray(properties)) return properties.length;
|
|
17
|
-
// DirectionalProperties object - using physical array length as representative, since the length for logical is the same
|
|
18
|
-
return properties.physical?.length ?? 0;
|
|
19
|
-
};
|
|
20
12
|
|
|
21
13
|
/**
|
|
22
14
|
* Orders all properties by the most dependent props
|
|
@@ -29,19 +21,19 @@ export const orderPropNames = config => Object.keys(config).sort((a, b) => {
|
|
|
29
21
|
} = config;
|
|
30
22
|
const {
|
|
31
23
|
property: aProp,
|
|
32
|
-
properties: aProperties
|
|
24
|
+
properties: aProperties = []
|
|
33
25
|
} = aConf;
|
|
34
26
|
const {
|
|
35
27
|
property: bProp,
|
|
36
|
-
properties: bProperties
|
|
28
|
+
properties: bProperties = []
|
|
37
29
|
} = bConf;
|
|
38
|
-
const aIsShorthand =
|
|
39
|
-
const bIsShorthand =
|
|
30
|
+
const aIsShorthand = SHORTHAND_PROPERTIES.includes(aProp);
|
|
31
|
+
const bIsShorthand = SHORTHAND_PROPERTIES.includes(bProp);
|
|
40
32
|
if (aIsShorthand && bIsShorthand) {
|
|
41
|
-
const aNum =
|
|
42
|
-
const bNum =
|
|
33
|
+
const aNum = aProperties.length;
|
|
34
|
+
const bNum = bProperties.length;
|
|
43
35
|
if (aProp !== bProp) {
|
|
44
|
-
return compare(
|
|
36
|
+
return compare(SHORTHAND_PROPERTIES.indexOf(aProp), SHORTHAND_PROPERTIES.indexOf(bProp));
|
|
45
37
|
}
|
|
46
38
|
if (aProp === bProp) {
|
|
47
39
|
if (aNum === 0) return SORT.A_BEFORE_B;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/variance",
|
|
3
3
|
"description": "Constraint based CSS in JS for building scalable design systems",
|
|
4
|
-
"version": "0.25.3-alpha.
|
|
4
|
+
"version": "0.25.3-alpha.f73629.0",
|
|
5
5
|
"author": "codecaaron <aaron@codecademy.com>",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"csstype": "^3.0.7",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"build": "nx build @codecademy/variance"
|
|
33
33
|
},
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "bc86647c14e137b537eb8460ae51834595e2831f"
|
|
36
36
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getPropertyMode } from './getPropertyMode';
|
|
2
|
-
describe('getPropertyMode', () => {
|
|
3
|
-
it.each([{
|
|
4
|
-
useLogicalProperties: true,
|
|
5
|
-
expected: 'logical'
|
|
6
|
-
}, {
|
|
7
|
-
useLogicalProperties: false,
|
|
8
|
-
expected: 'physical'
|
|
9
|
-
}])('returns "$expected" when useLogicalProperties is $useLogicalProperties', ({
|
|
10
|
-
useLogicalProperties,
|
|
11
|
-
expected
|
|
12
|
-
}) => {
|
|
13
|
-
expect(getPropertyMode(useLogicalProperties)).toBe(expected);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getPropertyMode';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getPropertyMode';
|