@codecademy/variance 0.25.1-alpha.fb9da9.0 → 0.25.1
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 +3 -13
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -2
- package/dist/types/config.d.ts +4 -9
- package/dist/types/properties.d.ts +0 -5
- package/dist/utils/propNames.js +3 -5
- 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
|
@@ -63,8 +63,7 @@ export const variance = {
|
|
|
63
63
|
transform = identity,
|
|
64
64
|
property,
|
|
65
65
|
properties = [property],
|
|
66
|
-
scale
|
|
67
|
-
resolveProperty
|
|
66
|
+
scale
|
|
68
67
|
} = config;
|
|
69
68
|
const getScaleValue = createScaleLookup(scale);
|
|
70
69
|
const alwaysTransform = scale === undefined || isArray(scale);
|
|
@@ -98,23 +97,14 @@ export const variance = {
|
|
|
98
97
|
// for each property look up the scale value from theme if passed and apply any
|
|
99
98
|
// final transforms to the value
|
|
100
99
|
properties.forEach(property => {
|
|
101
|
-
// Resolve directional properties if resolveProperty hook is provided
|
|
102
|
-
let resolvedProperty;
|
|
103
|
-
if (resolveProperty && typeof property === 'object') {
|
|
104
|
-
const useLogicalProperties = props.theme?.useLogicalProperties ?? true;
|
|
105
|
-
const mode = resolveProperty(useLogicalProperties);
|
|
106
|
-
resolvedProperty = property[mode];
|
|
107
|
-
} else {
|
|
108
|
-
resolvedProperty = property;
|
|
109
|
-
}
|
|
110
100
|
let styleValue = intermediateValue;
|
|
111
101
|
if (useTransform && !isUndefined(styleValue)) {
|
|
112
|
-
styleValue = transform(styleValue,
|
|
102
|
+
styleValue = transform(styleValue, property, props);
|
|
113
103
|
}
|
|
114
104
|
switch (typeof styleValue) {
|
|
115
105
|
case 'number':
|
|
116
106
|
case 'string':
|
|
117
|
-
return styles[
|
|
107
|
+
return styles[property] = styleValue;
|
|
118
108
|
case 'object':
|
|
119
109
|
return Object.assign(styles, styleValue);
|
|
120
110
|
default:
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types/config.d.ts
CHANGED
|
@@ -1,21 +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
|
-
/** Hook to resolve directional properties (physical/logical) based on theme setting */
|
|
18
|
-
resolveProperty?: (useLogicalProperties: boolean) => PropertyMode;
|
|
19
16
|
}
|
|
20
17
|
export interface AbstractPropTransformer extends Prop {
|
|
21
18
|
prop: string;
|
|
@@ -27,8 +24,7 @@ export interface AbstractParser {
|
|
|
27
24
|
config: Record<string, AbstractPropTransformer>;
|
|
28
25
|
}
|
|
29
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[]>;
|
|
30
|
-
type
|
|
31
|
-
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>;
|
|
32
28
|
export type Scale<Config extends Prop> = ResponsiveProp<ScaleValue<Config> | ((theme: Theme) => ScaleValue<Config>)>;
|
|
33
29
|
export interface TransformFn<P extends string, Config extends Prop> {
|
|
34
30
|
(value: Scale<Config> | Scale<Config>, prop: P, props: ThemeProps<{
|
|
@@ -73,4 +69,3 @@ export type SystemProps<P extends AbstractParser> = {
|
|
|
73
69
|
export type VariantProps<T extends string, V> = {
|
|
74
70
|
[Key in T]?: V;
|
|
75
71
|
};
|
|
76
|
-
export {};
|
|
@@ -19,9 +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
22
|
export {};
|
package/dist/utils/propNames.js
CHANGED
|
@@ -9,8 +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
12
|
|
|
15
13
|
/**
|
|
16
14
|
* Orders all properties by the most dependent props
|
|
@@ -29,13 +27,13 @@ export const orderPropNames = config => Object.keys(config).sort((a, b) => {
|
|
|
29
27
|
property: bProp,
|
|
30
28
|
properties: bProperties = []
|
|
31
29
|
} = bConf;
|
|
32
|
-
const aIsShorthand =
|
|
33
|
-
const bIsShorthand =
|
|
30
|
+
const aIsShorthand = SHORTHAND_PROPERTIES.includes(aProp);
|
|
31
|
+
const bIsShorthand = SHORTHAND_PROPERTIES.includes(bProp);
|
|
34
32
|
if (aIsShorthand && bIsShorthand) {
|
|
35
33
|
const aNum = aProperties.length;
|
|
36
34
|
const bNum = bProperties.length;
|
|
37
35
|
if (aProp !== bProp) {
|
|
38
|
-
return compare(
|
|
36
|
+
return compare(SHORTHAND_PROPERTIES.indexOf(aProp), SHORTHAND_PROPERTIES.indexOf(bProp));
|
|
39
37
|
}
|
|
40
38
|
if (aProp === bProp) {
|
|
41
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.1
|
|
4
|
+
"version": "0.25.1",
|
|
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": "38f5368f7245ab5a33464954c842405231edcd16"
|
|
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';
|