@atlaskit/primitives 0.4.1 → 0.5.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/CHANGELOG.md +12 -0
- package/dist/cjs/components/box.js +15 -11
- package/dist/cjs/components/internal/base-box.partial.js +3 -3
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/internal/style-maps.js +130 -0
- package/dist/cjs/internal/xcss.js +122 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/components/box.js +14 -6
- package/dist/es2019/components/internal/base-box.partial.js +2 -2
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/internal/style-maps.js +117 -0
- package/dist/es2019/internal/xcss.js +104 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/components/box.js +16 -8
- package/dist/esm/components/internal/base-box.partial.js +3 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/internal/style-maps.js +117 -0
- package/dist/esm/internal/xcss.js +111 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/components/box.d.ts +4 -3
- package/dist/types/components/inline.partial.d.ts +5 -2
- package/dist/types/components/internal/base-box.partial.d.ts +42 -3
- package/dist/types/components/stack.partial.d.ts +4 -1
- package/dist/types/components/types.d.ts +9 -14
- package/dist/types/index.d.ts +1 -0
- package/dist/types/internal/style-maps.d.ts +151 -0
- package/dist/types/internal/xcss.d.ts +51 -0
- package/package.json +3 -2
- package/report.api.md +263 -35
- package/tmp/api-report-tmp.d.ts +227 -10
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
|
|
2
|
+
import { css as cssEmotion } from '@emotion/react';
|
|
3
|
+
import { backgroundColorMap, borderColorMap, borderRadiusMap, borderWidthMap, dimensionMap, paddingMap, textColorMap } from './style-maps';
|
|
4
|
+
const tokensMap = {
|
|
5
|
+
backgroundColor: backgroundColorMap,
|
|
6
|
+
borderColor: borderColorMap,
|
|
7
|
+
borderRadius: borderRadiusMap,
|
|
8
|
+
borderWidth: borderWidthMap,
|
|
9
|
+
color: textColorMap,
|
|
10
|
+
height: dimensionMap,
|
|
11
|
+
maxHeight: dimensionMap,
|
|
12
|
+
maxWidth: dimensionMap,
|
|
13
|
+
minHeight: dimensionMap,
|
|
14
|
+
minWidth: dimensionMap,
|
|
15
|
+
padding: paddingMap,
|
|
16
|
+
paddingBlock: paddingMap,
|
|
17
|
+
paddingBlockEnd: paddingMap,
|
|
18
|
+
paddingBlockStart: paddingMap,
|
|
19
|
+
paddingInline: paddingMap,
|
|
20
|
+
paddingInlineEnd: paddingMap,
|
|
21
|
+
paddingInlineStart: paddingMap,
|
|
22
|
+
width: dimensionMap
|
|
23
|
+
};
|
|
24
|
+
const uniqueSymbol = Symbol('Internal symbol to verify xcss function is called safely');
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Only exposed for testing.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export const transformStyles = styleObj => {
|
|
31
|
+
if (!styleObj || typeof styleObj !== 'object') {
|
|
32
|
+
return styleObj;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// If styles are defined as an CSSObject[], recursively call on each element until we reach CSSObject
|
|
36
|
+
if (Array.isArray(styleObj)) {
|
|
37
|
+
return styleObj.map(transformStyles);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Modifies styleObj in place. Be careful.
|
|
41
|
+
Object.entries(styleObj).forEach(([key, value]) => {
|
|
42
|
+
var _process, _process$env;
|
|
43
|
+
if (((_process = process) === null || _process === void 0 ? void 0 : (_process$env = _process.env) === null || _process$env === void 0 ? void 0 : _process$env.NODE_ENV) === 'development') {
|
|
44
|
+
// We don't support `.class`, `[data-testid]`, `> *`, `#some-id`
|
|
45
|
+
if (/(\.|\s|&+|\*\>|#|\[.*\])/.test(key)) {
|
|
46
|
+
throw new Error(`Styles not supported for key '${key}'.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// If key is a pseudo class or a pseudo element, then value should be an object.
|
|
51
|
+
// So, call transformStyles on the value
|
|
52
|
+
if (/^::?.*$/.test(key)) {
|
|
53
|
+
styleObj[key] = transformStyles(value);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// TODO: Deal with media queries
|
|
58
|
+
|
|
59
|
+
// We have now dealt with all the special cases, so,
|
|
60
|
+
// check whether what remains is a style property
|
|
61
|
+
// that can be transformed.
|
|
62
|
+
if (!(key in tokensMap)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const tokenValue = tokensMap[key][value];
|
|
66
|
+
if (!tokenValue) {
|
|
67
|
+
throw new Error('Invalid Token');
|
|
68
|
+
}
|
|
69
|
+
styleObj[key] = tokenValue;
|
|
70
|
+
});
|
|
71
|
+
return styleObj;
|
|
72
|
+
};
|
|
73
|
+
const baseXcss = style => {
|
|
74
|
+
const transformedStyles = transformStyles(style);
|
|
75
|
+
return {
|
|
76
|
+
symbol: uniqueSymbol,
|
|
77
|
+
styles: cssEmotion(transformedStyles)
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @internal used in primitives
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
export const parseXcss = args => {
|
|
86
|
+
if (Array.isArray(args)) {
|
|
87
|
+
// @ts-expect-error FIXME
|
|
88
|
+
return args.map(parseXcss);
|
|
89
|
+
}
|
|
90
|
+
const {
|
|
91
|
+
symbol,
|
|
92
|
+
styles
|
|
93
|
+
} = args;
|
|
94
|
+
if (typeof process && process.env.NODE_ENV === 'development' && symbol !== uniqueSymbol) {
|
|
95
|
+
throw new Error('Styles generated from unsafe source, use the `xcss` export from `@atlaskit/primitives`.');
|
|
96
|
+
}
|
|
97
|
+
return styles;
|
|
98
|
+
};
|
|
99
|
+
// unused private functions only so we can extract the return type from a generic function
|
|
100
|
+
const boxWrapper = style => xcss(style);
|
|
101
|
+
const inlineWrapper = style => xcss(style);
|
|
102
|
+
export function xcss(style) {
|
|
103
|
+
return baseXcss(style);
|
|
104
|
+
}
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["as", "children", "color", "backgroundColor", "shadow", "borderStyle", "borderWidth", "borderRadius", "borderColor", "layer", "flex", "flexGrow", "flexShrink", "alignSelf", "overflow", "overflowInline", "overflowBlock", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "height", "width", "display", "position", "
|
|
4
|
-
_excluded2 = ["
|
|
5
|
-
|
|
3
|
+
var _excluded = ["as", "children", "color", "backgroundColor", "shadow", "borderStyle", "borderWidth", "borderRadius", "borderColor", "layer", "flex", "flexGrow", "flexShrink", "alignSelf", "overflow", "overflowInline", "overflowBlock", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "height", "width", "display", "position", "style", "testId", "xcss"],
|
|
4
|
+
_excluded2 = ["className"];
|
|
5
|
+
/** @jsx jsx */
|
|
6
|
+
import { forwardRef } from 'react';
|
|
7
|
+
import { jsx } from '@emotion/react';
|
|
8
|
+
import { parseXcss } from '../internal/xcss';
|
|
6
9
|
import { BaseBox } from './internal/base-box.partial';
|
|
7
10
|
/**
|
|
8
11
|
* __Box__
|
|
@@ -45,13 +48,14 @@ var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
45
48
|
display = _ref$display === void 0 ? 'block' : _ref$display,
|
|
46
49
|
_ref$position = _ref.position,
|
|
47
50
|
position = _ref$position === void 0 ? 'static' : _ref$position,
|
|
48
|
-
|
|
51
|
+
style = _ref.style,
|
|
49
52
|
testId = _ref.testId,
|
|
53
|
+
xcss = _ref.xcss,
|
|
50
54
|
htmlAttributes = _objectWithoutProperties(_ref, _excluded);
|
|
51
|
-
var
|
|
52
|
-
className = htmlAttributes.className,
|
|
55
|
+
var spreadClass = htmlAttributes.className,
|
|
53
56
|
safeHtmlAttributes = _objectWithoutProperties(htmlAttributes, _excluded2);
|
|
54
|
-
|
|
57
|
+
var className = xcss && parseXcss(xcss);
|
|
58
|
+
return jsx(BaseBox, _extends({
|
|
55
59
|
as: as,
|
|
56
60
|
color: color,
|
|
57
61
|
backgroundColor: backgroundColor,
|
|
@@ -79,9 +83,13 @@ var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
79
83
|
width: width,
|
|
80
84
|
display: display,
|
|
81
85
|
position: position,
|
|
82
|
-
|
|
86
|
+
style: style,
|
|
83
87
|
testId: testId,
|
|
84
88
|
ref: ref
|
|
89
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
90
|
+
,
|
|
91
|
+
css: className
|
|
85
92
|
}, safeHtmlAttributes), children);
|
|
86
93
|
});
|
|
94
|
+
Box.displayName = 'Box';
|
|
87
95
|
export default Box;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
var _excluded = ["as", "className", "children", "color", "backgroundColor", "shadow", "borderStyle", "borderWidth", "borderRadius", "borderColor", "layer", "flex", "flexGrow", "flexShrink", "alignSelf", "overflow", "overflowInline", "overflowBlock", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "height", "width", "display", "position", "
|
|
4
|
+
var _excluded = ["as", "className", "children", "color", "backgroundColor", "shadow", "borderStyle", "borderWidth", "borderRadius", "borderColor", "layer", "flex", "flexGrow", "flexShrink", "alignSelf", "overflow", "overflowInline", "overflowBlock", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "height", "width", "display", "position", "style", "testId"];
|
|
5
5
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
7
|
/** @jsx jsx */
|
|
@@ -81,11 +81,11 @@ export var BaseBox = /*#__PURE__*/forwardRef(function (_ref3, ref) {
|
|
|
81
81
|
display = _ref3$display === void 0 ? displayMap.block : _ref3$display,
|
|
82
82
|
_ref3$position = _ref3.position,
|
|
83
83
|
position = _ref3$position === void 0 ? 'static' : _ref3$position,
|
|
84
|
-
|
|
84
|
+
style = _ref3.style,
|
|
85
85
|
testId = _ref3.testId,
|
|
86
86
|
htmlAttributes = _objectWithoutProperties(_ref3, _excluded);
|
|
87
87
|
var Component = as || 'div';
|
|
88
|
-
var inlineStyles = Object.assign({},
|
|
88
|
+
var inlineStyles = Object.assign({}, style, getResponsiveVars('borderWidth', borderWidth, borderWidthMap), getResponsiveVars('display', display, displayMap), getResponsiveVars('padding', padding, paddingMap), getResponsiveVars('paddingBlock', paddingBlock, paddingMap), getResponsiveVars('paddingBlockStart', paddingBlockStart, paddingMap), getResponsiveVars('paddingBlockEnd', paddingBlockEnd, paddingMap), getResponsiveVars('paddingInline', paddingInline, paddingMap), getResponsiveVars('paddingInlineStart', paddingInlineStart, paddingMap), getResponsiveVars('paddingInlineEnd', paddingInlineEnd, paddingMap));
|
|
89
89
|
var node = jsx(Component, _extends({
|
|
90
90
|
style: inlineStyles,
|
|
91
91
|
ref: ref
|
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/no-unsafe-design-token-usage */
|
|
2
|
+
|
|
3
|
+
// TODO: All of these maps need to be codegen'd
|
|
4
|
+
export var backgroundColorMap = {
|
|
5
|
+
disabled: "var(--ds-background-disabled, #091e4289)",
|
|
6
|
+
input: "var(--ds-background-input, #FAFBFC)",
|
|
7
|
+
'inverse.subtle': "var(--ds-background-inverse-subtle, #00000029)",
|
|
8
|
+
neutral: "var(--ds-background-neutral, #DFE1E6)",
|
|
9
|
+
'neutral.subtle': "var(--ds-background-neutral-subtle, transparent)",
|
|
10
|
+
'neutral.bold': "var(--ds-background-neutral-bold, #42526E)",
|
|
11
|
+
selected: "var(--ds-background-selected, #DEEBFF)",
|
|
12
|
+
'selected.bold': "var(--ds-background-selected-bold, #0052CC)",
|
|
13
|
+
'brand.bold': "var(--ds-background-brand-bold, #0052CC)",
|
|
14
|
+
danger: "var(--ds-background-danger, #FFEBE6)",
|
|
15
|
+
'danger.bold': "var(--ds-background-danger-bold, #DE350B)",
|
|
16
|
+
warning: "var(--ds-background-warning, #FFFAE6)",
|
|
17
|
+
'warning.bold': "var(--ds-background-warning-bold, #FFAB00)",
|
|
18
|
+
success: "var(--ds-background-success, #E3FCEF)",
|
|
19
|
+
'success.bold': "var(--ds-background-success-bold, #00875A)",
|
|
20
|
+
discovery: "var(--ds-background-discovery, #EAE6FF)",
|
|
21
|
+
'discovery.bold': "var(--ds-background-discovery-bold, #5243AA)",
|
|
22
|
+
information: "var(--ds-background-information, #DEEBFF)",
|
|
23
|
+
'information.bold': "var(--ds-background-information-bold, #0052CC)",
|
|
24
|
+
'color.blanket': "var(--ds-blanket, #091e4289)",
|
|
25
|
+
'color.blanket.selected': "var(--ds-blanket-selected, #388BFF14)",
|
|
26
|
+
'color.blanket.danger': "var(--ds-blanket-danger, #EF5C4814)",
|
|
27
|
+
'elevation.surface': "var(--ds-surface, #FFFFFF)",
|
|
28
|
+
'elevation.surface.overlay': "var(--ds-surface-overlay, #FFFFFF)",
|
|
29
|
+
'elevation.surface.raised': "var(--ds-surface-raised, #FFFFFF)",
|
|
30
|
+
'elevation.surface.sunken': "var(--ds-surface-sunken, #F4F5F7)"
|
|
31
|
+
};
|
|
32
|
+
export var borderColorMap = {
|
|
33
|
+
'color.border': "var(--ds-border, #091e4221)",
|
|
34
|
+
disabled: "var(--ds-border-disabled, #FAFBFC)",
|
|
35
|
+
focused: "var(--ds-border-focused, #4C9AFF)",
|
|
36
|
+
input: "var(--ds-border-input, #FAFBFC)",
|
|
37
|
+
inverse: "var(--ds-border-inverse, #FFFFFF)",
|
|
38
|
+
selected: "var(--ds-border-selected, #0052CC)",
|
|
39
|
+
brand: "var(--ds-border-brand, #0052CC)",
|
|
40
|
+
danger: "var(--ds-border-danger, #FF5630)",
|
|
41
|
+
warning: "var(--ds-border-warning, #FFC400)",
|
|
42
|
+
success: "var(--ds-border-success, #00875A)",
|
|
43
|
+
discovery: "var(--ds-border-discovery, #998DD9)",
|
|
44
|
+
information: "var(--ds-border-information, #0065FF)",
|
|
45
|
+
bold: "var(--ds-border-bold, #344563)"
|
|
46
|
+
};
|
|
47
|
+
export var borderWidthMap = {
|
|
48
|
+
'size.0': "var(--ds-width-0, 0)",
|
|
49
|
+
'size.050': "var(--ds-width-050, 1px)",
|
|
50
|
+
'size.100': "var(--ds-width-100, 2px)"
|
|
51
|
+
};
|
|
52
|
+
export var borderRadiusMap = {
|
|
53
|
+
'radius.400': "var(--ds-radius-400, 16px)",
|
|
54
|
+
'radius.300': "var(--ds-radius-300, 12px)",
|
|
55
|
+
'radius.100': "var(--ds-radius-100, 4px)",
|
|
56
|
+
'radius.050': "var(--ds-radius-050, 2px)",
|
|
57
|
+
'radius.200': "var(--ds-radius-200, 8px)"
|
|
58
|
+
};
|
|
59
|
+
export var paddingMap = {
|
|
60
|
+
'space.0': "var(--ds-space-0, 0px)",
|
|
61
|
+
'space.025': "var(--ds-space-025, 2px)",
|
|
62
|
+
'space.050': "var(--ds-space-050, 4px)",
|
|
63
|
+
'space.075': "var(--ds-space-075, 6px)",
|
|
64
|
+
'space.100': "var(--ds-space-100, 8px)",
|
|
65
|
+
'space.150': "var(--ds-space-150, 12px)",
|
|
66
|
+
'space.200': "var(--ds-space-200, 16px)",
|
|
67
|
+
'space.250': "var(--ds-space-250, 20px)",
|
|
68
|
+
'space.300': "var(--ds-space-300, 24px)",
|
|
69
|
+
'space.400': "var(--ds-space-400, 32px)",
|
|
70
|
+
'space.500': "var(--ds-space-500, 40px)",
|
|
71
|
+
'space.600': "var(--ds-space-600, 48px)",
|
|
72
|
+
'space.800': "var(--ds-space-800, 64px)",
|
|
73
|
+
'space.1000': "var(--ds-space-1000, 80px)"
|
|
74
|
+
};
|
|
75
|
+
export var textColorMap = {
|
|
76
|
+
'color.text': "var(--ds-text, #172B4D)",
|
|
77
|
+
'accent.red': "var(--ds-text-accent-red, #DE350B)",
|
|
78
|
+
'accent.red.bolder': "var(--ds-text-accent-red-bolder, #BF2600)",
|
|
79
|
+
'accent.orange': "var(--ds-text-accent-orange, #F18D13)",
|
|
80
|
+
'accent.orange.bolder': "var(--ds-text-accent-orange-bolder, #B65C02)",
|
|
81
|
+
'accent.yellow': "var(--ds-text-accent-yellow, #FF991F)",
|
|
82
|
+
'accent.yellow.bolder': "var(--ds-text-accent-yellow-bolder, #FF8B00)",
|
|
83
|
+
'accent.green': "var(--ds-text-accent-green, #00875A)",
|
|
84
|
+
'accent.green.bolder': "var(--ds-text-accent-green-bolder, #006644)",
|
|
85
|
+
'accent.teal': "var(--ds-text-accent-teal, #00A3BF)",
|
|
86
|
+
'accent.teal.bolder': "var(--ds-text-accent-teal-bolder, #008DA6)",
|
|
87
|
+
'accent.blue': "var(--ds-text-accent-blue, #0052CC)",
|
|
88
|
+
'accent.blue.bolder': "var(--ds-text-accent-blue-bolder, #0747A6)",
|
|
89
|
+
'accent.purple': "var(--ds-text-accent-purple, #5243AA)",
|
|
90
|
+
'accent.purple.bolder': "var(--ds-text-accent-purple-bolder, #403294)",
|
|
91
|
+
'accent.magenta': "var(--ds-text-accent-magenta, #E774BB)",
|
|
92
|
+
'accent.magenta.bolder': "var(--ds-text-accent-magenta-bolder, #DA62AC)",
|
|
93
|
+
'accent.gray': "var(--ds-text-accent-gray, #505F79)",
|
|
94
|
+
'accent.gray.bolder': "var(--ds-text-accent-gray-bolder, #172B4D)",
|
|
95
|
+
disabled: "var(--ds-text-disabled, #A5ADBA)",
|
|
96
|
+
inverse: "var(--ds-text-inverse, #FFFFFF)",
|
|
97
|
+
selected: "var(--ds-text-selected, #0052CC)",
|
|
98
|
+
brand: "var(--ds-text-brand, #0065FF)",
|
|
99
|
+
danger: "var(--ds-text-danger, #DE350B)",
|
|
100
|
+
warning: "var(--ds-text-warning, #974F0C)",
|
|
101
|
+
'warning.inverse': "var(--ds-text-warning-inverse, #172B4D)",
|
|
102
|
+
success: "var(--ds-text-success, #006644)",
|
|
103
|
+
discovery: "var(--ds-text-discovery, #403294)",
|
|
104
|
+
information: "var(--ds-text-information, #0052CC)",
|
|
105
|
+
subtlest: "var(--ds-text-subtlest, #7A869A)",
|
|
106
|
+
subtle: "var(--ds-text-subtle, #42526E)"
|
|
107
|
+
};
|
|
108
|
+
export var dimensionMap = {
|
|
109
|
+
'100%': '100%',
|
|
110
|
+
'size.100': '16px',
|
|
111
|
+
'size.200': '24px',
|
|
112
|
+
'size.300': '32px',
|
|
113
|
+
'size.400': '40px',
|
|
114
|
+
'size.500': '48px',
|
|
115
|
+
'size.600': '96px',
|
|
116
|
+
'size.1000': '192px'
|
|
117
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
3
|
+
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
|
|
4
|
+
import { css as cssEmotion } from '@emotion/react';
|
|
5
|
+
import { backgroundColorMap, borderColorMap, borderRadiusMap, borderWidthMap, dimensionMap, paddingMap, textColorMap } from './style-maps';
|
|
6
|
+
var tokensMap = {
|
|
7
|
+
backgroundColor: backgroundColorMap,
|
|
8
|
+
borderColor: borderColorMap,
|
|
9
|
+
borderRadius: borderRadiusMap,
|
|
10
|
+
borderWidth: borderWidthMap,
|
|
11
|
+
color: textColorMap,
|
|
12
|
+
height: dimensionMap,
|
|
13
|
+
maxHeight: dimensionMap,
|
|
14
|
+
maxWidth: dimensionMap,
|
|
15
|
+
minHeight: dimensionMap,
|
|
16
|
+
minWidth: dimensionMap,
|
|
17
|
+
padding: paddingMap,
|
|
18
|
+
paddingBlock: paddingMap,
|
|
19
|
+
paddingBlockEnd: paddingMap,
|
|
20
|
+
paddingBlockStart: paddingMap,
|
|
21
|
+
paddingInline: paddingMap,
|
|
22
|
+
paddingInlineEnd: paddingMap,
|
|
23
|
+
paddingInlineStart: paddingMap,
|
|
24
|
+
width: dimensionMap
|
|
25
|
+
};
|
|
26
|
+
var uniqueSymbol = Symbol('Internal symbol to verify xcss function is called safely');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Only exposed for testing.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export var transformStyles = function transformStyles(styleObj) {
|
|
33
|
+
if (!styleObj || _typeof(styleObj) !== 'object') {
|
|
34
|
+
return styleObj;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// If styles are defined as an CSSObject[], recursively call on each element until we reach CSSObject
|
|
38
|
+
if (Array.isArray(styleObj)) {
|
|
39
|
+
return styleObj.map(transformStyles);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Modifies styleObj in place. Be careful.
|
|
43
|
+
Object.entries(styleObj).forEach(function (_ref) {
|
|
44
|
+
var _process, _process$env;
|
|
45
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
46
|
+
key = _ref2[0],
|
|
47
|
+
value = _ref2[1];
|
|
48
|
+
if (((_process = process) === null || _process === void 0 ? void 0 : (_process$env = _process.env) === null || _process$env === void 0 ? void 0 : _process$env.NODE_ENV) === 'development') {
|
|
49
|
+
// We don't support `.class`, `[data-testid]`, `> *`, `#some-id`
|
|
50
|
+
if (/(\.|\s|&+|\*\>|#|\[.*\])/.test(key)) {
|
|
51
|
+
throw new Error("Styles not supported for key '".concat(key, "'."));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// If key is a pseudo class or a pseudo element, then value should be an object.
|
|
56
|
+
// So, call transformStyles on the value
|
|
57
|
+
if (/^::?.*$/.test(key)) {
|
|
58
|
+
styleObj[key] = transformStyles(value);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// TODO: Deal with media queries
|
|
63
|
+
|
|
64
|
+
// We have now dealt with all the special cases, so,
|
|
65
|
+
// check whether what remains is a style property
|
|
66
|
+
// that can be transformed.
|
|
67
|
+
if (!(key in tokensMap)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
var tokenValue = tokensMap[key][value];
|
|
71
|
+
if (!tokenValue) {
|
|
72
|
+
throw new Error('Invalid Token');
|
|
73
|
+
}
|
|
74
|
+
styleObj[key] = tokenValue;
|
|
75
|
+
});
|
|
76
|
+
return styleObj;
|
|
77
|
+
};
|
|
78
|
+
var baseXcss = function baseXcss(style) {
|
|
79
|
+
var transformedStyles = transformStyles(style);
|
|
80
|
+
return {
|
|
81
|
+
symbol: uniqueSymbol,
|
|
82
|
+
styles: cssEmotion(transformedStyles)
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @internal used in primitives
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
export var parseXcss = function parseXcss(args) {
|
|
91
|
+
if (Array.isArray(args)) {
|
|
92
|
+
// @ts-expect-error FIXME
|
|
93
|
+
return args.map(parseXcss);
|
|
94
|
+
}
|
|
95
|
+
var symbol = args.symbol,
|
|
96
|
+
styles = args.styles;
|
|
97
|
+
if ((typeof process === "undefined" ? "undefined" : _typeof(process)) && process.env.NODE_ENV === 'development' && symbol !== uniqueSymbol) {
|
|
98
|
+
throw new Error('Styles generated from unsafe source, use the `xcss` export from `@atlaskit/primitives`.');
|
|
99
|
+
}
|
|
100
|
+
return styles;
|
|
101
|
+
};
|
|
102
|
+
// unused private functions only so we can extract the return type from a generic function
|
|
103
|
+
var boxWrapper = function boxWrapper(style) {
|
|
104
|
+
return xcss(style);
|
|
105
|
+
};
|
|
106
|
+
var inlineWrapper = function inlineWrapper(style) {
|
|
107
|
+
return xcss(style);
|
|
108
|
+
};
|
|
109
|
+
export function xcss(style) {
|
|
110
|
+
return baseXcss(style);
|
|
111
|
+
}
|
package/dist/esm/version.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
1
2
|
import { ElementType, FC, ReactElement } from 'react';
|
|
2
3
|
import { BaseBoxProps } from './internal/base-box.partial';
|
|
3
|
-
import { BoxResponsiveProp } from './internal/types';
|
|
4
|
-
import { PublicBoxPropsBase } from './types';
|
|
5
|
-
export declare type BoxProps<T extends ElementType = 'div'> = Omit<BaseBoxProps<T>, 'className' |
|
|
4
|
+
import type { BoxResponsiveProp } from './internal/types';
|
|
5
|
+
import type { PublicBoxPropsBase } from './types';
|
|
6
|
+
export declare type BoxProps<T extends ElementType = 'div'> = Omit<BaseBoxProps<T>, 'className' | BoxResponsiveProp> & PublicBoxPropsBase;
|
|
6
7
|
declare type BoxComponent<T extends ElementType = 'div'> = (<T extends ElementType = 'div'>(props: BoxProps<T>) => ReactElement | null) & FC<BoxProps<T>>;
|
|
7
8
|
/**
|
|
8
9
|
* __Box__
|
|
@@ -43,9 +43,12 @@ export interface InlineProps<T extends ElementType = 'div'> {
|
|
|
43
43
|
*/
|
|
44
44
|
testId?: string;
|
|
45
45
|
/**
|
|
46
|
-
* Elements to be rendered inside the
|
|
46
|
+
* Elements to be rendered inside the Inline.
|
|
47
47
|
*/
|
|
48
48
|
children: ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* Forwarded ref element
|
|
51
|
+
*/
|
|
49
52
|
ref?: ComponentPropsWithRef<T>['ref'];
|
|
50
53
|
}
|
|
51
54
|
export declare type AlignInline = 'start' | 'center' | 'end';
|
|
@@ -109,5 +112,5 @@ export declare type RowSpace = keyof typeof rowSpaceMap;
|
|
|
109
112
|
* ```
|
|
110
113
|
*
|
|
111
114
|
*/
|
|
112
|
-
declare const Inline: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Pick<InlineProps<ElementType<any>>, "
|
|
115
|
+
declare const Inline: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Pick<InlineProps<ElementType<any>>, "as" | "children" | "testId" | "alignInline" | "alignBlock" | "shouldWrap" | "spread" | "grow" | "space" | "rowSpace" | "separator"> & import("react").RefAttributes<any>>>;
|
|
113
116
|
export default Inline;
|
|
@@ -3,7 +3,7 @@ import { ComponentPropsWithoutRef, ComponentPropsWithRef, ElementType, FC, React
|
|
|
3
3
|
import { Layer } from '../../constants';
|
|
4
4
|
import { ResponsiveObject } from '../../helpers/responsive';
|
|
5
5
|
import type { BasePrimitiveProps } from '../types';
|
|
6
|
-
export declare type BaseBoxProps<T extends ElementType = 'div'> = Omit<ComponentPropsWithoutRef<T>, 'as' | 'className'
|
|
6
|
+
export declare type BaseBoxProps<T extends ElementType = 'div'> = Omit<ComponentPropsWithoutRef<T>, 'as' | 'className'> & BasePrimitiveProps & BaseBoxPropsFoundation<T>;
|
|
7
7
|
declare type BaseBoxPropsFoundation<T extends ElementType> = {
|
|
8
8
|
/**
|
|
9
9
|
* The DOM element to render as the Box. Defaults to `div`.
|
|
@@ -26,54 +26,80 @@ declare type BaseBoxPropsFoundation<T extends ElementType> = {
|
|
|
26
26
|
*/
|
|
27
27
|
children?: ReactNode;
|
|
28
28
|
/**
|
|
29
|
+
* @private
|
|
30
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
29
31
|
* Token representing color with a fallback.
|
|
30
32
|
*/
|
|
31
33
|
color?: TextColor;
|
|
32
34
|
/**
|
|
35
|
+
* @private
|
|
36
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
33
37
|
* Token representing background color with a fallback.
|
|
34
38
|
*/
|
|
35
39
|
backgroundColor?: BackgroundColor;
|
|
36
40
|
/**
|
|
41
|
+
* @private
|
|
42
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
37
43
|
* Token representing shadow with a fallback
|
|
38
44
|
*/
|
|
39
45
|
shadow?: Shadow;
|
|
40
46
|
/**
|
|
47
|
+
* @private
|
|
48
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
41
49
|
* Defines border style.
|
|
42
50
|
*/
|
|
43
51
|
borderStyle?: BorderStyle;
|
|
44
52
|
/**
|
|
53
|
+
* @private
|
|
54
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
45
55
|
* Defines border width.
|
|
46
56
|
*/
|
|
47
57
|
borderWidth?: BorderWidth | ResponsiveObject<BorderWidth>;
|
|
48
58
|
/**
|
|
59
|
+
* @private
|
|
60
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
49
61
|
* Token representing border color with a fallback.
|
|
50
62
|
*/
|
|
51
63
|
borderColor?: BorderColor;
|
|
52
64
|
/**
|
|
65
|
+
* @private
|
|
66
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
53
67
|
* Defines border radius.
|
|
54
68
|
*/
|
|
55
69
|
borderRadius?: BorderRadius;
|
|
56
70
|
/**
|
|
71
|
+
* @private
|
|
72
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
57
73
|
* Used for providing a z-index.
|
|
58
74
|
*/
|
|
59
75
|
layer?: Layer;
|
|
60
76
|
/**
|
|
77
|
+
* @private
|
|
78
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
61
79
|
* Shorthand `flex` property.
|
|
62
80
|
*/
|
|
63
81
|
flex?: Flex;
|
|
64
82
|
/**
|
|
83
|
+
* @private
|
|
84
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
65
85
|
* Defines the flex grow factor -- how much remaining space should be taken up.
|
|
66
86
|
*/
|
|
67
87
|
flexGrow?: FlexGrow;
|
|
68
88
|
/**
|
|
89
|
+
* @private
|
|
90
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
69
91
|
* Defines the flex shrink factor -- how the item will shrink relative to other flex items in the container.
|
|
70
92
|
*/
|
|
71
93
|
flexShrink?: FlexShrink;
|
|
72
94
|
/**
|
|
95
|
+
* @private
|
|
96
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
73
97
|
* Overrides the `align-items` value.
|
|
74
98
|
*/
|
|
75
99
|
alignSelf?: AlignSelf;
|
|
76
100
|
/**
|
|
101
|
+
* @private
|
|
102
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
77
103
|
* Defines what happens if content overflows the box.
|
|
78
104
|
* Shorthand for overflow-inline and overflow-block.
|
|
79
105
|
*
|
|
@@ -82,10 +108,14 @@ declare type BaseBoxPropsFoundation<T extends ElementType> = {
|
|
|
82
108
|
*/
|
|
83
109
|
overflow?: Overflow;
|
|
84
110
|
/**
|
|
111
|
+
* @private
|
|
112
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
85
113
|
* Defines what happens if content overflows the box in the horizontal direction (inline).
|
|
86
114
|
*/
|
|
87
115
|
overflowInline?: OverflowInline;
|
|
88
116
|
/**
|
|
117
|
+
* @private
|
|
118
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
89
119
|
* Defines what happens if content overflows the box in the vertical direction (block).
|
|
90
120
|
*/
|
|
91
121
|
overflowBlock?: OverflowBlock;
|
|
@@ -127,23 +157,32 @@ declare type BaseBoxPropsFoundation<T extends ElementType> = {
|
|
|
127
157
|
*/
|
|
128
158
|
paddingInlineEnd?: PaddingInlineEnd | ResponsiveObject<PaddingInlineEnd>;
|
|
129
159
|
/**
|
|
160
|
+
* @private
|
|
161
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
130
162
|
* Token representing width.
|
|
131
|
-
* @experimental The existing tokens will be replaced to better reflect dimensions.
|
|
132
163
|
*/
|
|
133
164
|
width?: Width;
|
|
134
165
|
/**
|
|
166
|
+
* @private
|
|
167
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
135
168
|
* Token representing height.
|
|
136
|
-
* @experimental The existing tokens will be replaced to better reflect dimensions.
|
|
137
169
|
*/
|
|
138
170
|
height?: Height;
|
|
139
171
|
/**
|
|
172
|
+
* @private
|
|
173
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
140
174
|
* Defines display type and layout. Defaults to `block`.
|
|
141
175
|
*/
|
|
142
176
|
display?: Display | ResponsiveObject<Display>;
|
|
143
177
|
/**
|
|
178
|
+
* @private
|
|
179
|
+
* @deprecated Use `xcss` to achieve this functionality.
|
|
144
180
|
* CSS position property.
|
|
145
181
|
*/
|
|
146
182
|
position?: Position;
|
|
183
|
+
/**
|
|
184
|
+
* Forwarded ref element
|
|
185
|
+
*/
|
|
147
186
|
ref?: ComponentPropsWithRef<T>['ref'];
|
|
148
187
|
};
|
|
149
188
|
export declare type BaseBoxComponent<T extends ElementType = 'div'> = (<T extends ElementType = 'div'>(props: BaseBoxProps<T>) => ReactElement | null) & FC<BaseBoxProps<T>>;
|
|
@@ -33,6 +33,9 @@ export interface StackProps<T extends ElementType = 'div'> {
|
|
|
33
33
|
* Elements to be rendered inside the Stack.
|
|
34
34
|
*/
|
|
35
35
|
children: ReactNode;
|
|
36
|
+
/**
|
|
37
|
+
* Forwarded ref element
|
|
38
|
+
*/
|
|
36
39
|
ref?: ComponentPropsWithRef<T>['ref'];
|
|
37
40
|
}
|
|
38
41
|
export declare type AlignInline = 'start' | 'center' | 'end';
|
|
@@ -78,5 +81,5 @@ export declare type Space = keyof typeof spaceMap;
|
|
|
78
81
|
* ```
|
|
79
82
|
*
|
|
80
83
|
*/
|
|
81
|
-
declare const Stack: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Pick<StackProps<ElementType<any>>, "
|
|
84
|
+
declare const Stack: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Pick<StackProps<ElementType<any>>, "as" | "children" | "testId" | "alignInline" | "alignBlock" | "spread" | "grow" | "space"> & import("react").RefAttributes<any>>>;
|
|
82
85
|
export default Stack;
|