@atlaskit/primitives 0.4.0 → 0.4.2

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/components/box.js +20 -17
  3. package/dist/cjs/components/inline.partial.js +4 -2
  4. package/dist/cjs/components/internal/base-box.partial.js +3 -3
  5. package/dist/cjs/components/stack.partial.js +4 -2
  6. package/dist/cjs/index.js +7 -0
  7. package/dist/cjs/internal/style-maps.js +130 -0
  8. package/dist/cjs/internal/xcss.js +110 -0
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/components/box.js +19 -12
  11. package/dist/es2019/components/inline.partial.js +3 -1
  12. package/dist/es2019/components/internal/base-box.partial.js +2 -2
  13. package/dist/es2019/components/stack.partial.js +3 -1
  14. package/dist/es2019/index.js +1 -0
  15. package/dist/es2019/internal/style-maps.js +117 -0
  16. package/dist/es2019/internal/xcss.js +97 -0
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/components/box.js +21 -14
  19. package/dist/esm/components/inline.partial.js +4 -2
  20. package/dist/esm/components/internal/base-box.partial.js +3 -3
  21. package/dist/esm/components/stack.partial.js +4 -2
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/internal/style-maps.js +117 -0
  24. package/dist/esm/internal/xcss.js +100 -0
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/components/box.d.ts +9 -7
  27. package/dist/types/components/inline.partial.d.ts +8 -3
  28. package/dist/types/components/internal/base-box.partial.d.ts +43 -4
  29. package/dist/types/components/stack.partial.d.ts +8 -3
  30. package/dist/types/components/types.d.ts +9 -14
  31. package/dist/types/index.d.ts +1 -0
  32. package/dist/types/internal/style-maps.d.ts +151 -0
  33. package/dist/types/internal/xcss.d.ts +22 -0
  34. package/package.json +3 -2
  35. package/report.api.md +240 -38
  36. package/tmp/api-report-tmp.d.ts +209 -13
@@ -3,12 +3,12 @@ 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' | 'style'> & BasePrimitiveProps & BaseBoxPropsFoundation<T>;
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`.
10
10
  */
11
- as?: 'div' | 'span';
11
+ as?: 'div' | 'span' | 'li';
12
12
  /**
13
13
  * The HTML className attribute.
14
14
  *
@@ -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>>;
@@ -1,6 +1,10 @@
1
1
  /** @jsx jsx */
2
- import { ReactNode } from 'react';
3
- export interface StackProps {
2
+ import { ComponentPropsWithRef, ElementType, ReactNode } from 'react';
3
+ export interface StackProps<T extends ElementType = 'div'> {
4
+ /**
5
+ * The DOM element to render as the Stack. Defaults to `div`.
6
+ */
7
+ as?: 'div' | 'span' | 'ul' | 'ol';
4
8
  /**
5
9
  * Used to align children along the main axis.
6
10
  */
@@ -29,6 +33,7 @@ export interface StackProps {
29
33
  * Elements to be rendered inside the Stack.
30
34
  */
31
35
  children: ReactNode;
36
+ ref?: ComponentPropsWithRef<T>['ref'];
32
37
  }
33
38
  export declare type AlignInline = 'start' | 'center' | 'end';
34
39
  export declare type AlignBlock = 'start' | 'center' | 'end';
@@ -73,5 +78,5 @@ export declare type Space = keyof typeof spaceMap;
73
78
  * ```
74
79
  *
75
80
  */
76
- declare const Stack: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<StackProps & import("react").RefAttributes<HTMLDivElement>>>;
81
+ declare const Stack: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Pick<StackProps<ElementType<any>>, "space" | "as" | "children" | "testId" | "alignInline" | "alignBlock" | "spread" | "grow"> & import("react").RefAttributes<any>>>;
77
82
  export default Stack;
@@ -1,24 +1,16 @@
1
1
  import type { CSSProperties } from 'react';
2
- import { BorderWidth, Display, Padding, PaddingBlock, PaddingBlockEnd, PaddingBlockStart, PaddingInline, PaddingInlineEnd, PaddingInlineStart } from './internal/base-box.partial';
3
- /**
4
- * Restricted set of inline styles to be applied to the primitive.
5
- * Should be avoided where possible, in favor of the pre-defined props and values on the primitive itself.
6
- * Tokens should be used where possible.
7
- */
8
- export declare type CustomStyles = Pick<CSSProperties, 'flexBasis' | 'flex' | 'width' | 'height' | 'minWidth' | 'maxWidth' | 'minHeight' | 'maxHeight' | 'insetInlineStart' | 'insetInlineEnd' | 'insetBlockStart' | 'float' | 'margin' | 'marginInlineStart' | 'marginInlineEnd' | 'marginBlockStart' | 'marginBlockEnd' | 'marginInline' | 'marginBlock' | 'paddingLeft' | 'paddingRight' | 'paddingTop' | 'paddingBottom'>;
9
- export interface BasePrimitiveProps {
2
+ import type { SafeCSS } from '../internal/xcss';
3
+ import type { BorderWidth, Display, Padding, PaddingBlock, PaddingBlockEnd, PaddingBlockStart, PaddingInline, PaddingInlineEnd, PaddingInlineStart } from './internal/base-box.partial';
4
+ export declare type BasePrimitiveProps = {
10
5
  /**
11
6
  * A unique string that appears as data attribute `data-testid` in the rendered code, serving as a hook for automated tests.
12
7
  */
13
8
  testId?: string;
14
9
  /**
15
10
  * Inline styles to be applied to the primitive.
16
- * Marked as "unsafe" because any CSS properties can be provided here without any extra control or validation, including those that would be better managed by the primitive itself via props.
17
- * Effectively equivalent to the standard `style` prop but marked with a special name.
18
- * Used only internally.
19
11
  */
20
- UNSAFE_style?: CSSProperties;
21
- }
12
+ style?: CSSProperties;
13
+ };
22
14
  export declare type PublicBoxPropsBase = {
23
15
  /**
24
16
  * Defines border width.
@@ -65,5 +57,8 @@ export declare type PublicBoxPropsBase = {
65
57
  * Tokens representing CSS `paddingInlineEnd`.
66
58
  */
67
59
  paddingInlineEnd?: PaddingInlineEnd;
68
- customStyles?: CustomStyles;
60
+ /**
61
+ * Safe subset of styles that can be applied as a classname.
62
+ */
63
+ xcss?: SafeCSS;
69
64
  };
@@ -1,3 +1,4 @@
1
1
  export { default as Box, type BoxProps } from './components/box';
2
2
  export { default as Inline, type InlineProps, } from './components/inline.partial';
3
+ export { xcss } from './internal/xcss';
3
4
  export { default as Stack, type StackProps } from './components/stack.partial';
@@ -0,0 +1,151 @@
1
+ export declare const backgroundColorMap: {
2
+ readonly disabled: "var(--ds-background-disabled)";
3
+ readonly input: "var(--ds-background-input)";
4
+ readonly 'inverse.subtle': "var(--ds-background-inverse-subtle)";
5
+ readonly neutral: "var(--ds-background-neutral)";
6
+ readonly 'neutral.subtle': "var(--ds-background-neutral-subtle)";
7
+ readonly 'neutral.bold': "var(--ds-background-neutral-bold)";
8
+ readonly selected: "var(--ds-background-selected)";
9
+ readonly 'selected.bold': "var(--ds-background-selected-bold)";
10
+ readonly 'brand.bold': "var(--ds-background-brand-bold)";
11
+ readonly danger: "var(--ds-background-danger)";
12
+ readonly 'danger.bold': "var(--ds-background-danger-bold)";
13
+ readonly warning: "var(--ds-background-warning)";
14
+ readonly 'warning.bold': "var(--ds-background-warning-bold)";
15
+ readonly success: "var(--ds-background-success)";
16
+ readonly 'success.bold': "var(--ds-background-success-bold)";
17
+ readonly discovery: "var(--ds-background-discovery)";
18
+ readonly 'discovery.bold': "var(--ds-background-discovery-bold)";
19
+ readonly information: "var(--ds-background-information)";
20
+ readonly 'information.bold': "var(--ds-background-information-bold)";
21
+ readonly 'color.blanket': "var(--ds-blanket)";
22
+ readonly 'color.blanket.selected': "var(--ds-blanket-selected)";
23
+ readonly 'color.blanket.danger': "var(--ds-blanket-danger)";
24
+ readonly 'elevation.surface': "var(--ds-surface)";
25
+ readonly 'elevation.surface.overlay': "var(--ds-surface-overlay)";
26
+ readonly 'elevation.surface.raised': "var(--ds-surface-raised)";
27
+ readonly 'elevation.surface.sunken': "var(--ds-surface-sunken)";
28
+ };
29
+ export declare type BackgroundColor = keyof typeof backgroundColorMap;
30
+ export declare const borderColorMap: {
31
+ readonly 'color.border': "var(--ds-border)";
32
+ readonly disabled: "var(--ds-border-disabled)";
33
+ readonly focused: "var(--ds-border-focused)";
34
+ readonly input: "var(--ds-border-input)";
35
+ readonly inverse: "var(--ds-border-inverse)";
36
+ readonly selected: "var(--ds-border-selected)";
37
+ readonly brand: "var(--ds-border-brand)";
38
+ readonly danger: "var(--ds-border-danger)";
39
+ readonly warning: "var(--ds-border-warning)";
40
+ readonly success: "var(--ds-border-success)";
41
+ readonly discovery: "var(--ds-border-discovery)";
42
+ readonly information: "var(--ds-border-information)";
43
+ readonly bold: "var(--ds-border-bold)";
44
+ };
45
+ export declare type BorderColor = keyof typeof borderColorMap;
46
+ export declare const borderWidthMap: {
47
+ readonly 'size.0': "var(--ds-width-0)";
48
+ readonly 'size.050': "var(--ds-width-050)";
49
+ readonly 'size.100': "var(--ds-width-100)";
50
+ };
51
+ export declare type BorderWidth = keyof typeof borderWidthMap;
52
+ export declare const borderRadiusMap: {
53
+ readonly 'radius.400': "var(--ds-radius-400)";
54
+ readonly 'radius.300': "var(--ds-radius-300)";
55
+ readonly 'radius.100': "var(--ds-radius-100)";
56
+ readonly 'radius.050': "var(--ds-radius-050)";
57
+ readonly 'radius.200': "var(--ds-radius-200)";
58
+ };
59
+ export declare type BorderRadius = keyof typeof borderRadiusMap;
60
+ export declare const paddingMap: {
61
+ readonly 'space.0': "var(--ds-space-0)";
62
+ readonly 'space.025': "var(--ds-space-025)";
63
+ readonly 'space.050': "var(--ds-space-050)";
64
+ readonly 'space.075': "var(--ds-space-075)";
65
+ readonly 'space.100': "var(--ds-space-100)";
66
+ readonly 'space.150': "var(--ds-space-150)";
67
+ readonly 'space.200': "var(--ds-space-200)";
68
+ readonly 'space.250': "var(--ds-space-250)";
69
+ readonly 'space.300': "var(--ds-space-300)";
70
+ readonly 'space.400': "var(--ds-space-400)";
71
+ readonly 'space.500': "var(--ds-space-500)";
72
+ readonly 'space.600': "var(--ds-space-600)";
73
+ readonly 'space.800': "var(--ds-space-800)";
74
+ readonly 'space.1000': "var(--ds-space-1000)";
75
+ };
76
+ export declare type Padding = keyof typeof paddingMap;
77
+ export declare type PaddingBlock = keyof typeof paddingMap;
78
+ export declare type PaddingBlockStart = keyof typeof paddingMap;
79
+ export declare type PaddingBlockEnd = keyof typeof paddingMap;
80
+ export declare type PaddingInline = keyof typeof paddingMap;
81
+ export declare type PaddingInlineStart = keyof typeof paddingMap;
82
+ export declare type PaddingInlineEnd = keyof typeof paddingMap;
83
+ export declare const textColorMap: {
84
+ readonly 'color.text': "var(--ds-text)";
85
+ readonly 'accent.red': "var(--ds-text-accent-red)";
86
+ readonly 'accent.red.bolder': "var(--ds-text-accent-red-bolder)";
87
+ readonly 'accent.orange': "var(--ds-text-accent-orange)";
88
+ readonly 'accent.orange.bolder': "var(--ds-text-accent-orange-bolder)";
89
+ readonly 'accent.yellow': "var(--ds-text-accent-yellow)";
90
+ readonly 'accent.yellow.bolder': "var(--ds-text-accent-yellow-bolder)";
91
+ readonly 'accent.green': "var(--ds-text-accent-green)";
92
+ readonly 'accent.green.bolder': "var(--ds-text-accent-green-bolder)";
93
+ readonly 'accent.teal': "var(--ds-text-accent-teal)";
94
+ readonly 'accent.teal.bolder': "var(--ds-text-accent-teal-bolder)";
95
+ readonly 'accent.blue': "var(--ds-text-accent-blue)";
96
+ readonly 'accent.blue.bolder': "var(--ds-text-accent-blue-bolder)";
97
+ readonly 'accent.purple': "var(--ds-text-accent-purple)";
98
+ readonly 'accent.purple.bolder': "var(--ds-text-accent-purple-bolder)";
99
+ readonly 'accent.magenta': "var(--ds-text-accent-magenta)";
100
+ readonly 'accent.magenta.bolder': "var(--ds-text-accent-magenta-bolder)";
101
+ readonly 'accent.gray': "var(--ds-text-accent-gray)";
102
+ readonly 'accent.gray.bolder': "var(--ds-text-accent-gray-bolder)";
103
+ readonly disabled: "var(--ds-text-disabled)";
104
+ readonly inverse: "var(--ds-text-inverse)";
105
+ readonly selected: "var(--ds-text-selected)";
106
+ readonly brand: "var(--ds-text-brand)";
107
+ readonly danger: "var(--ds-text-danger)";
108
+ readonly warning: "var(--ds-text-warning)";
109
+ readonly 'warning.inverse': "var(--ds-text-warning-inverse)";
110
+ readonly success: "var(--ds-text-success)";
111
+ readonly discovery: "var(--ds-text-discovery)";
112
+ readonly information: "var(--ds-text-information)";
113
+ readonly subtlest: "var(--ds-text-subtlest)";
114
+ readonly subtle: "var(--ds-text-subtle)";
115
+ };
116
+ export declare type TextColor = keyof typeof textColorMap;
117
+ export declare const dimensionMap: {
118
+ readonly '100%': "100%";
119
+ readonly 'size.100': "16px";
120
+ readonly 'size.200': "24px";
121
+ readonly 'size.300': "32px";
122
+ readonly 'size.400': "40px";
123
+ readonly 'size.500': "48px";
124
+ readonly 'size.600': "96px";
125
+ readonly 'size.1000': "192px";
126
+ };
127
+ export declare type Width = keyof typeof dimensionMap;
128
+ export declare type Height = keyof typeof dimensionMap;
129
+ export declare type MinWidth = keyof typeof dimensionMap;
130
+ export declare type MaxWidth = keyof typeof dimensionMap;
131
+ export declare type MinHeight = keyof typeof dimensionMap;
132
+ export declare type MaxHeight = keyof typeof dimensionMap;
133
+ export declare type TokenisedProps = {
134
+ backgroundColor?: BackgroundColor;
135
+ borderColor?: BorderColor;
136
+ borderWidth?: BorderWidth;
137
+ color?: TextColor;
138
+ height?: Height;
139
+ minHeight?: MinHeight;
140
+ minWidth?: MinWidth;
141
+ maxHeight?: MaxHeight;
142
+ maxWidth?: MaxWidth;
143
+ padding?: Padding;
144
+ paddingBlock?: Padding;
145
+ paddingInline?: Padding;
146
+ paddingBlockStart?: Padding;
147
+ paddingBlockEnd?: Padding;
148
+ paddingInlineStart?: Padding;
149
+ paddingInlineEnd?: Padding;
150
+ width?: Width;
151
+ };
@@ -0,0 +1,22 @@
1
+ import { css as cssEmotion } from '@emotion/react';
2
+ import { CSSObject, CSSPropertiesWithMultiValues, CSSPseudos } from '@emotion/serialize';
3
+ import { TokenisedProps } from './style-maps';
4
+ declare const uniqueSymbol: unique symbol;
5
+ /**
6
+ * Only exposed for testing.
7
+ * @internal
8
+ */
9
+ export declare const transformStyles: (styleObj?: CSSObject | CSSObject[] | undefined) => CSSObject | CSSObject[] | undefined;
10
+ declare type XCSS = ReturnType<typeof xcss>;
11
+ export declare type SafeCSS = XCSS | XCSS[];
12
+ export declare type SafeCSSObject = CSSPseudos & TokenisedProps & Omit<CSSPropertiesWithMultiValues, keyof TokenisedProps>;
13
+ export declare const xcss: (style?: SafeCSSObject | SafeCSSObject[] | undefined) => {
14
+ readonly symbol: typeof uniqueSymbol;
15
+ readonly styles: import("@emotion/react").SerializedStyles;
16
+ };
17
+ /**
18
+ * @internal used in primitives
19
+ * @returns
20
+ */
21
+ export declare const parseXcss: (args: SafeCSS) => ReturnType<typeof cssEmotion>;
22
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Primitives are token-backed low-level building blocks.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -41,6 +41,7 @@
41
41
  "@atlaskit/tokens": "^1.2.0",
42
42
  "@babel/runtime": "^7.0.0",
43
43
  "@emotion/react": "^11.7.1",
44
+ "@emotion/serialize": "^1.1.0",
44
45
  "tiny-invariant": "^1.2.0"
45
46
  },
46
47
  "peerDependencies": {
@@ -88,4 +89,4 @@
88
89
  }
89
90
  },
90
91
  "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
91
- }
92
+ }