@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.
@@ -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 BoxXCSS } 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?: BoxXCSS;
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,51 @@
1
+ /// <reference types="react" />
2
+ import { css as cssEmotion } from '@emotion/react';
3
+ import { CSSObject, CSSPropertiesWithMultiValues, CSSPseudos, SerializedStyles } from '@emotion/serialize';
4
+ import { Box, Inline } from '../index';
5
+ import { TokenisedProps } from './style-maps';
6
+ declare const uniqueSymbol: unique symbol;
7
+ /**
8
+ * Only exposed for testing.
9
+ * @internal
10
+ */
11
+ export declare const transformStyles: (styleObj?: CSSObject | CSSObject[] | undefined) => CSSObject | CSSObject[] | undefined;
12
+ /**
13
+ * @internal used in primitives
14
+ * @returns
15
+ */
16
+ export declare const parseXcss: (args: SafeCSS) => ReturnType<typeof cssEmotion>;
17
+ declare type SafeCSSObject = CSSPseudos & TokenisedProps & Omit<CSSPropertiesWithMultiValues, keyof TokenisedProps>;
18
+ declare type ScopedSafeCSSObject<T extends keyof SafeCSSObject> = Pick<SafeCSSObject, T>;
19
+ declare const boxWrapper: (style: any) => {
20
+ readonly symbol: typeof uniqueSymbol;
21
+ readonly styles: BoxStyles;
22
+ };
23
+ declare const inlineWrapper: (style: any) => {
24
+ readonly symbol: typeof uniqueSymbol;
25
+ readonly styles: InlineStyles;
26
+ };
27
+ declare type XCSS = ReturnType<typeof boxWrapper> | ReturnType<typeof inlineWrapper>;
28
+ declare type SafeCSS = XCSS | XCSS[];
29
+ declare type AllowedBoxStyles = keyof SafeCSSObject;
30
+ declare type AllowedInlineStyles = 'backgroundColor' | 'padding';
31
+ export declare function xcss<Primitive extends typeof Box | typeof Inline = typeof Box>(style: Primitive extends typeof Box ? ScopedSafeCSSObject<AllowedBoxStyles> : Primitive extends typeof Inline ? ScopedSafeCSSObject<AllowedInlineStyles> : never): {
32
+ readonly symbol: typeof uniqueSymbol;
33
+ readonly styles: Primitive extends (<T extends import("react").ElementType<any> = "div">(props: import("../index").BoxProps<T>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null) & import("react").FC<import("../index").BoxProps<"div">> ? BoxStyles : Primitive extends import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Pick<import("../index").InlineProps<import("react").ElementType<any>>, "as" | "children" | "testId" | "alignInline" | "alignBlock" | "shouldWrap" | "spread" | "grow" | "space" | "rowSpace" | "separator"> & import("react").RefAttributes<any>>> ? InlineStyles : never;
34
+ };
35
+ declare const boxTag: unique symbol;
36
+ export declare type BoxStyles = SerializedStyles & {
37
+ [boxTag]: true;
38
+ };
39
+ export declare type BoxXCSS = {
40
+ readonly symbol: typeof uniqueSymbol;
41
+ readonly styles: BoxStyles;
42
+ };
43
+ declare const inlineTag: unique symbol;
44
+ export declare type InlineStyles = SerializedStyles & {
45
+ [inlineTag]: true;
46
+ };
47
+ export declare type InlineXCSS = {
48
+ readonly symbol: typeof uniqueSymbol;
49
+ readonly styles: InlineStyles;
50
+ };
51
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
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
+ }