@atlaskit/primitives 1.10.1 → 1.11.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 +6 -0
- package/constellation/box/examples.mdx +16 -8
- package/constellation/box/usage.mdx +12 -12
- package/constellation/inline/examples.mdx +15 -5
- package/constellation/inline/usage.mdx +9 -12
- package/constellation/stack/examples.mdx +18 -7
- package/constellation/stack/usage.mdx +7 -10
- package/constellation/xcss/examples.mdx +3 -3
- package/constellation/xcss/migration.mdx +13 -20
- package/constellation/xcss/usage.mdx +19 -18
- package/dist/cjs/xcss/style-maps.partial.js +38 -22
- package/dist/cjs/xcss/xcss.js +25 -0
- package/dist/es2019/xcss/style-maps.partial.js +36 -21
- package/dist/es2019/xcss/xcss.js +26 -1
- package/dist/esm/xcss/style-maps.partial.js +36 -21
- package/dist/esm/xcss/xcss.js +26 -1
- package/dist/types/xcss/style-maps.partial.d.ts +64 -23
- package/dist/types-ts4.5/xcss/style-maps.partial.d.ts +64 -23
- package/package.json +8 -29
- package/report.api.md +34 -0
- package/scripts/__tests__/__snapshots__/codegen.test.tsx.snap +73 -1
- package/scripts/__tests__/codegen.test.tsx +21 -4
- package/scripts/codegen-styles.tsx +13 -1
- package/scripts/color-codegen-template.tsx +0 -15
- package/scripts/elevation-codegen-template.tsx +94 -0
- package/tmp/api-report-tmp.d.ts +34 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/primitives
|
|
2
2
|
|
|
3
|
+
## 1.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#43366](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43366) [`f1d3719ea48`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f1d3719ea48) - Tokenised values are now accepted in all border-radius, border-width, border-color, and opacity CSS properties in XCSS.
|
|
8
|
+
|
|
3
9
|
## 1.10.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -8,6 +8,7 @@ import BoxBasic from '../../examples/constellation/box/basic';
|
|
|
8
8
|
import BoxPadding from '../../examples/constellation/box/padding';
|
|
9
9
|
import BoxBackgroundColor from '../../examples/constellation/box/background-color';
|
|
10
10
|
import BoxXcss from '../../examples/constellation/box/xcss';
|
|
11
|
+
import BoxConditional from '../../examples/constellation/box/conditional-styles';
|
|
11
12
|
import BoxPracticalUseCase from '../../examples/constellation/box/practical-use-case';
|
|
12
13
|
|
|
13
14
|
import { CodeDocsHeader } from '@af/design-system-docs-ui';
|
|
@@ -20,38 +21,45 @@ import { CodeDocsHeader } from '@af/design-system-docs-ui';
|
|
|
20
21
|
|
|
21
22
|
## Basic
|
|
22
23
|
|
|
23
|
-
Box is a general-purpose container that allows for controlled use of design tokens. Use the given props to configure display
|
|
24
|
-
[
|
|
24
|
+
Box is a general-purpose container that allows for controlled use of design tokens. Use the given props to configure display behavior and styling that aligns with the Atlassian Design System.
|
|
25
|
+
Use [XCSS](/components/primitives/xcss/usage) to style primitive components safely with tokens.
|
|
25
26
|
|
|
26
27
|
<Example Component={BoxBasic} packageName="@atlaskit/primitives/box" />
|
|
27
28
|
|
|
28
29
|
## Padding
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
Use padding props to access spacing design tokens and control internal layout. The following example demonstrates how each prop works with space tokens.
|
|
31
32
|
|
|
32
33
|
<Example Component={BoxPadding} packageName="@atlaskit/primitives/box" />
|
|
33
34
|
|
|
34
|
-
The nomenclature used by these props follows [logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties). This naming is used to support different [writing modes](https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode) in
|
|
35
|
+
The nomenclature used by these props follows [logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties). This naming is used to support different [writing modes](https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode) in Atlassian products.
|
|
35
36
|
|
|
36
37
|
## Background color
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
Box accepts a wide variety of background colors, referenced as semantic design tokens. For the full list of color tokens, visit the [token list](/components/tokens/all-tokens).
|
|
39
40
|
|
|
40
41
|
<Example
|
|
41
42
|
Component={BoxBackgroundColor}
|
|
42
43
|
packageName="@atlaskit/primitives/box"
|
|
43
44
|
/>
|
|
44
45
|
|
|
45
|
-
##
|
|
46
|
+
## XCSS
|
|
46
47
|
|
|
47
48
|
Box exposes an `xcss` prop. This prop accepts `xcss` function calls that contain a subset of permitted styles. When used with `Box`, `xcss` accepts most CSS properties, and when a token exists, the rule accepts that token as a value.
|
|
48
|
-
|
|
49
|
+
|
|
50
|
+
For more information on XCSS, see the dedicated [XCSS documentation](/components/primitives/xcss).
|
|
49
51
|
|
|
50
52
|
<Example Component={BoxXcss} packageName="@atlaskit/primitives/box" />
|
|
51
53
|
|
|
54
|
+
## Conditional styles
|
|
55
|
+
|
|
56
|
+
To achieve conditional styles, it is usually simpler to apply conditional behavior at the `xcss` object level, rather than applying conditional behavior to individual properties.
|
|
57
|
+
|
|
58
|
+
<Example Component={BoxConditional} packageName="@atlaskit/primitives/box" />
|
|
59
|
+
|
|
52
60
|
## Practical use case
|
|
53
61
|
|
|
54
|
-
|
|
62
|
+
Box is designed to be used in conjunction with the inline and stack components to create layouts. This example demonstrates how these can be used to create familiar components and patterns.
|
|
55
63
|
|
|
56
64
|
<Example
|
|
57
65
|
Component={BoxPracticalUseCase}
|
|
@@ -4,12 +4,19 @@ description: A box is a generic container that provides managed access to design
|
|
|
4
4
|
order: 2
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
A
|
|
7
|
+
A box is a generic container that provides convenient and managed access to design tokens, and built-in guidance for the best practices of the Atlassian Design System. Use box in conjunction with other layout components such as [inline](/components/primitives/inline/usage) and [stack](/components/primitives/stack/usage) to easily create customized layouts.
|
|
8
|
+
|
|
8
9
|
Use a box to compose layouts and add styling to child elements through visual props, including spacing and color through design tokens.
|
|
9
10
|
|
|
11
|
+
## Using box
|
|
12
|
+
|
|
13
|
+
To identify usages of box in a given design, look for where a UI element will receive some visual styles applied to a container. Box can be used on a range of sizes of elements, from buttons to section wrappers.
|
|
14
|
+
|
|
15
|
+
Box, being generic in nature, can be "over-used", so it’s important to consider situations where more specific and expressive primitives could be used. For example, use [inline](/components/primitives/inline/usage) and [stack](/components/primitives/stack/usage) to manage horizontal and vertical layouts, respectively.
|
|
16
|
+
|
|
10
17
|
## Styling
|
|
11
18
|
|
|
12
|
-
Display behavior is set by using the available props or using
|
|
19
|
+
Display behavior is set by using the available props or using [XCSS](/components/primitives/xcss/usage). Makers can make design decisions for box by setting:
|
|
13
20
|
|
|
14
21
|
- `padding`
|
|
15
22
|
- `paddingInline`
|
|
@@ -20,15 +27,8 @@ Display behavior is set by using the available props or using `xcss`. Makers can
|
|
|
20
27
|
- `paddingBlockEnd`
|
|
21
28
|
- `backgroundColor`
|
|
22
29
|
|
|
23
|
-
## Using box
|
|
24
|
-
|
|
25
|
-
To identify usages of `Box` in a given design, look for where a UI element will receive some visual styles applied to a container. `Box` can be used on a range of sizes of elements, from buttons to section wrappers.
|
|
26
|
-
`Box`, being generic in nature, can be "over-used", so it’s important to consider situations where more specific and expressive primitives could be used, for example: `Inline` and `Stack` to manage horizontal and vertical layouts, respectively.
|
|
27
|
-
|
|
28
30
|
## Related
|
|
29
31
|
|
|
30
|
-
- [
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
33
|
-
- [Learn more about the Bleed primitive](/components/primitives/bleed/examples)
|
|
34
|
-
- [Learn more about the Flex primitive](/components/primitives/flex/examples)
|
|
32
|
+
- [Manage horizontal layout using an inline component](/components/primitives/inline/usage)
|
|
33
|
+
- [Manage vertical layout using a stack component](/components/primitives/stack/usage)
|
|
34
|
+
- [Use design tokens in code with XCSS](/components/primitives/XCSS/usage)
|
|
@@ -26,7 +26,7 @@ import { CodeDocsHeader } from '@af/design-system-docs-ui';
|
|
|
26
26
|
|
|
27
27
|
## Basic
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
Use an inline component to configure the layout of a group of elements horizontally.
|
|
30
30
|
|
|
31
31
|
Use the given props to configure display behavior using design tokens, as shown in the more complex examples below.
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ Use the given props to configure display behavior using design tokens, as shown
|
|
|
34
34
|
|
|
35
35
|
## Space
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
Control the spacing between items with the `space` prop.
|
|
38
38
|
|
|
39
39
|
<Example
|
|
40
40
|
Component={InlineSpaceBasic}
|
|
@@ -50,6 +50,16 @@ For a different space value between rows use the `rowSpace` prop.
|
|
|
50
50
|
packageName="@atlaskit/primitives/inline"
|
|
51
51
|
/>
|
|
52
52
|
|
|
53
|
+
## Reverse content
|
|
54
|
+
|
|
55
|
+
`flex-direction: `row-reverse` is a pattern that has [accessibility concerns](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction#accessibility_concerns) so inline doesn't support it.
|
|
56
|
+
|
|
57
|
+
If reversing content is required, we generally recommend to use JavaScript to reverse the JSX content thereby preserving the tabbing order.
|
|
58
|
+
|
|
59
|
+
In situations where tabbing order changes based on different breakpoints, then we have [show](/components/primitives/responsive/hide/examples) and [hide](/components/primitives/responsive/hide/examples) components that enable switching between different orderings of content.
|
|
60
|
+
|
|
61
|
+
For non-tabbable content that needs to be reversed, `flex-direction: row-reverse` is supported in XCSS. However, please be aware that we may lint against this in the future.
|
|
62
|
+
|
|
53
63
|
## Alignment
|
|
54
64
|
|
|
55
65
|
To control the alignment of items you can use the `alignBlock` and `alignInline` props which control alignment in the vertical and horizontal axis respectively.
|
|
@@ -76,7 +86,7 @@ Elements can be set to stay together, spaced at the given value (default behavio
|
|
|
76
86
|
|
|
77
87
|
## Wrap
|
|
78
88
|
|
|
79
|
-
When the number of items goes beyond the available space `shouldWrap`
|
|
89
|
+
When the number of items goes beyond the available space, use `shouldWrap` to create new rows of content.
|
|
80
90
|
|
|
81
91
|
<Example Component={InlineWrap} packageName="@atlaskit/primitives/inline" />
|
|
82
92
|
|
|
@@ -92,7 +102,7 @@ For logically related elements it's possible to specify a `separator` character
|
|
|
92
102
|
## Width control
|
|
93
103
|
|
|
94
104
|
By default an `Inline` will have its width influenced by the context where it appears.
|
|
95
|
-
To control the width, the `grow` prop
|
|
105
|
+
To control the width, use the `grow` prop with the values:
|
|
96
106
|
|
|
97
107
|
- `hug` (default) to use space only as required by its children, or
|
|
98
108
|
- `fill` to take all space provided by the parent element.
|
|
@@ -107,7 +117,7 @@ It's possible to control the rendered HTML element with the `as` prop.
|
|
|
107
117
|
|
|
108
118
|
## Practical use case
|
|
109
119
|
|
|
110
|
-
An example of how an
|
|
120
|
+
An example of how an inline component might be used in product, using Atlassian Design System components.
|
|
111
121
|
|
|
112
122
|
<Example
|
|
113
123
|
Component={InlinePracticalUseCase}
|
|
@@ -4,11 +4,11 @@ description: An inline manages the horizontal layout of direct children using fl
|
|
|
4
4
|
order: 2
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Use the inline component in conjunction with other layout components such as [box](/components/primitives/box/usage) and [stack](/components/primitives/stack/usage) to easily create customized layouts, with built-in guidance from the Atlassian Design System.
|
|
8
8
|
|
|
9
|
-
Inline
|
|
9
|
+
Inline components act as container to decide the horizontal layout of its children. They decide the specifics of how the children are displayed, for example, where they are aligned or how much space is between child elements. An inline component should be used purely for visual alignment, and should have no opinions about the functionality of its children.
|
|
10
10
|
|
|
11
|
-
In its simplest form,
|
|
11
|
+
In its simplest form, an inline component operates like a flexbox row, however adds the built in design token support and guidance.
|
|
12
12
|
|
|
13
13
|
```jsx
|
|
14
14
|
<Inline space="space.100" alignInline="center" alignBlock="start">
|
|
@@ -18,11 +18,11 @@ In its simplest form, `Inline` operates like a flexbox row, however adds the bui
|
|
|
18
18
|
|
|
19
19
|
Inline also has a `flex-direction: row;`. This is the default for flexbox, so it is not explicitly applied.
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Using inline
|
|
22
22
|
|
|
23
|
-
The purpose of an
|
|
23
|
+
The purpose of an inline is primarily as a container element controlling how child components are displayed and positioned horizontally. An inline should be used any time you wish to layout elements or components horizontally.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Use the inline props to customize the spacing and styling on any child elements. These include:
|
|
26
26
|
|
|
27
27
|
- `alignBlock`
|
|
28
28
|
- `alignInline`
|
|
@@ -35,9 +35,6 @@ The inline props can then be used to customize the spacing and styling on any ch
|
|
|
35
35
|
|
|
36
36
|
## Related
|
|
37
37
|
|
|
38
|
-
- [
|
|
39
|
-
- [
|
|
40
|
-
- [
|
|
41
|
-
- [Grid](/components/primitives/grid/examples)
|
|
42
|
-
- [Bleed](/components/primitives/bleed/examples)
|
|
43
|
-
- [Flex](/components/primitives/flex/examples)
|
|
38
|
+
- [Use box for a generic container with access to design tokens](/components/primitives/box/usage)
|
|
39
|
+
- [Manage vertical layout using a stack component](/components/primitives/stack/usage)
|
|
40
|
+
- [Use design tokens in code with XCSS](/components/primitives/XCSS/usage)
|
|
@@ -23,20 +23,31 @@ import { CodeDocsHeader } from '@af/design-system-docs-ui';
|
|
|
23
23
|
|
|
24
24
|
## Basic
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Use a stack component to efficiently lay-out a group of elements vertically.
|
|
27
|
+
|
|
27
28
|
Use the given props to configure display behavior using designs tokens, as shown in the more complex examples below.
|
|
28
29
|
|
|
29
30
|
<Example Component={StackBasic} packageName="@atlaskit/primitives/stack" />
|
|
30
31
|
|
|
31
32
|
## Space
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
Control spacing between items with the `space` prop.
|
|
34
35
|
|
|
35
36
|
<Example Component={StackSpaceBasic} packageName="@atlaskit/primitives/stack" />
|
|
36
37
|
|
|
38
|
+
## Reverse content
|
|
39
|
+
|
|
40
|
+
`flex-direction: `column-reverse` is a pattern that has [accessibility concerns](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction#accessibility_concerns) so stack doesn't support it.
|
|
41
|
+
|
|
42
|
+
If reversing content is required, we generally recommend to use JavaScript to reverse the JSX content thereby preserving the tabbing order.
|
|
43
|
+
|
|
44
|
+
In situations where tabbing order changes based on different breakpoints, then we have [show](/components/primitives/responsive/show/examples) and [hide](/components/primitives/responsive/hide/examples) components that enable switching between different orderings of content.
|
|
45
|
+
|
|
46
|
+
For non-tabbable content that needs to be reversed, `flex-direction: column-reverse` is supported in XCSS. However, please be aware that we may lint against this in the future.
|
|
47
|
+
|
|
37
48
|
## Alignment
|
|
38
49
|
|
|
39
|
-
|
|
50
|
+
Control the alignment of items using the `alignBlock` and `alignInline` props which control alignment in the vertical and horizontal axis respectively.
|
|
40
51
|
|
|
41
52
|
### Block alignment
|
|
42
53
|
|
|
@@ -51,15 +62,13 @@ To control the alignment of items you can use the `alignBlock` and `alignInline`
|
|
|
51
62
|
|
|
52
63
|
## Spread
|
|
53
64
|
|
|
54
|
-
|
|
65
|
+
Use the `spread` prop to set elements to stay together, spaced at the given value (default behavior) or spread equally in the space available.
|
|
55
66
|
|
|
56
67
|
<Example Component={StackSpread} packageName="@atlaskit/primitives/stack" />
|
|
57
68
|
|
|
58
69
|
## Width control
|
|
59
70
|
|
|
60
|
-
By default a `Stack` will have its width influenced by the context where it appears. To control the width the `grow` prop
|
|
61
|
-
|
|
62
|
-
To control that the `grow` prop can be used with the values:
|
|
71
|
+
By default a `Stack` will have its width influenced by the context where it appears. To control the width use the `grow` prop with the values:
|
|
63
72
|
|
|
64
73
|
- `hug` (default) to use space only as required by its children, or
|
|
65
74
|
- `fill` to take all space provided by the parent element.
|
|
@@ -74,6 +83,8 @@ It's possible to control the rendered HTML element with the `as` prop.
|
|
|
74
83
|
|
|
75
84
|
## Practical use case
|
|
76
85
|
|
|
86
|
+
An example of how a stack component might be used in product, using Atlassian Design System components.
|
|
87
|
+
|
|
77
88
|
<Example
|
|
78
89
|
Component={StackPracticalUseCase}
|
|
79
90
|
packageName="@atlaskit/primitives/stack"
|
|
@@ -4,9 +4,9 @@ description: A stack manages the vertical layout of direct children using flexbo
|
|
|
4
4
|
order: 2
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Use the stack component in conjunction with other layout components such as [box](/components/primitives/box/usage) and [inline](/components/primitives/inline/usage) to easily create customized layouts, with built-in guidance from the Atlassian Design System.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
A stack component aligns content vertically on a page or layout, acting as a container that decides the vertical layout of its children. Stack components also decide the specifics of how the children are displayed, for example, where they are aligned or how much space is between child elements. Stack is purely for visual alignment, and should have no opinions about the functionality of its children.
|
|
10
10
|
|
|
11
11
|
In its simplest form, `Stack` works like a flexbox column, with built-in design token support and guidance.
|
|
12
12
|
|
|
@@ -16,9 +16,9 @@ In its simplest form, `Stack` works like a flexbox column, with built-in design
|
|
|
16
16
|
</Stack>
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Using stack
|
|
20
20
|
|
|
21
|
-
A
|
|
21
|
+
A stack is primarily a container element controlling how content is displayed and aligned vertically. Use stack any time you wish to lay out elements or components vertically.
|
|
22
22
|
|
|
23
23
|
These props customize the spacing and styling of any child elements:
|
|
24
24
|
|
|
@@ -30,9 +30,6 @@ These props customize the spacing and styling of any child elements:
|
|
|
30
30
|
|
|
31
31
|
## Related
|
|
32
32
|
|
|
33
|
-
- [
|
|
34
|
-
- [
|
|
35
|
-
- [
|
|
36
|
-
- [Grid](/components/primitives/grid/examples)
|
|
37
|
-
- [Bleed](/components/primitives/bleed/examples)
|
|
38
|
-
- [Flex](/components/primitives/flex/examples)
|
|
33
|
+
- [Use box for a generic container with access to design tokens](/components/primitives/box/usage)
|
|
34
|
+
- [Manage horizontal layout using an inline component](/components/primitives/inline/usage)
|
|
35
|
+
- [Use design tokens in code with XCSS](/components/primitives/XCSS/usage)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: XCSS
|
|
3
|
-
description:
|
|
3
|
+
description: XCSS is a safer, tokens-first approach to CSS-in-JS.
|
|
4
4
|
order: 1
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -19,7 +19,7 @@ import { CodeDocsHeader } from '@af/design-system-docs-ui';
|
|
|
19
19
|
|
|
20
20
|
## Basic
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
XCSS can pull together different types of interactions and UI in a safer, more composable way.
|
|
23
23
|
|
|
24
24
|
<Example Component={xcssBasic} packageName="@atlaskit/primitives/xcss" />
|
|
25
25
|
|
|
@@ -31,7 +31,7 @@ To enable interactivity, use familiar selectors like `:hover` and `:focus-visibl
|
|
|
31
31
|
|
|
32
32
|
## Responsiveness
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
XCSS also accepts a subset of media queries at [predefined breakpoints](/components/primitives/responsive/breakpoints/examples).
|
|
35
35
|
|
|
36
36
|
<Example Component={xcssResponsive} packageName="@atlaskit/primitives/xcss" />
|
|
37
37
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Migrating your app to XCSS
|
|
3
|
-
description:
|
|
3
|
+
description: XCSS is a safer, tokens-first approach to CSS-in-JS.
|
|
4
4
|
order: 2
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ order: 2
|
|
|
8
8
|
|
|
9
9
|
### Changes for developers
|
|
10
10
|
|
|
11
|
-
There are two key changes to be mindful of when migrating to
|
|
11
|
+
There are two key changes to be mindful of when migrating to XCSS.
|
|
12
12
|
The first is updating callsites to remove any nested styles and
|
|
13
|
-
|
|
13
|
+
tokenized values.
|
|
14
14
|
|
|
15
15
|
```diff
|
|
16
16
|
- import { css } from '@emotion/react';
|
|
@@ -21,13 +21,12 @@ tokenised values.
|
|
|
21
21
|
// token based properties will no longer need to be wrapped
|
|
22
22
|
- padding: token('space.100'),
|
|
23
23
|
+ padding: 'space.100'
|
|
24
|
-
// no change is required for non-
|
|
24
|
+
// no change is required for non-tokenized values
|
|
25
25
|
transform: 'scale(2)'
|
|
26
26
|
});
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
The second change is that for the `xcss` function to be applied correctly it must be applied on a
|
|
30
|
-
component with an `xcss` JSXAttribute. This won't work with the `css` or `className`
|
|
29
|
+
The second change is that for the `xcss` function to be applied correctly it must be applied on a component with an `xcss` JSXAttribute. This won't work with the `css` or `className`
|
|
31
30
|
JSXAttributes, be aware if you're not seeing your styles appear.
|
|
32
31
|
|
|
33
32
|
```diff
|
|
@@ -35,9 +34,9 @@ JSXAttributes, be aware if you're not seeing your styles appear.
|
|
|
35
34
|
+ <Box xcss={someStyles} />
|
|
36
35
|
```
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
### Changing the way you express styles
|
|
39
38
|
|
|
40
|
-
Why are nested selectors a problem? A key philosophy of
|
|
39
|
+
Why are nested selectors a problem? A key philosophy of XCSS is encouraging more deterministic style application. Restricting nested styles eliminates side-effects and encourages component encapsulation. Consider the below example:
|
|
41
40
|
|
|
42
41
|
```tsx
|
|
43
42
|
const myComponentStyles = css({
|
|
@@ -77,13 +76,13 @@ const MyComponent = () => (
|
|
|
77
76
|
|
|
78
77
|
There will likely be cases where nesting is the only option. While not desirable, nesting can be used minimally, and when the potential impact is considered.
|
|
79
78
|
|
|
80
|
-
|
|
79
|
+
## FAQ
|
|
81
80
|
|
|
82
|
-
Migration to
|
|
81
|
+
Migration to XCSS is simple for the majority of cases. Here are some common strategies for migrations.
|
|
83
82
|
|
|
84
|
-
|
|
83
|
+
### Non-tokenized values
|
|
85
84
|
|
|
86
|
-
Before migrating to tokens, there are two options. Migrate to tokens first and then on a second pass migrate to
|
|
85
|
+
Before migrating to tokens, there are two options. Migrate to tokens first and then on a second pass migrate to XCSS or make the jump directly to use both tokens and XCSS.
|
|
87
86
|
|
|
88
87
|
```tsx
|
|
89
88
|
const someStyles = css({
|
|
@@ -101,10 +100,10 @@ const someStyles = xcss({
|
|
|
101
100
|
});
|
|
102
101
|
```
|
|
103
102
|
|
|
104
|
-
|
|
103
|
+
### Moving from the `styled` API
|
|
105
104
|
|
|
106
105
|
If currently using the `styled` API there are a few steps to migrate.
|
|
107
|
-
The safest approach is to use object styles, migrate to tokens (optionally) and then migrate to
|
|
106
|
+
The safest approach is to use object styles, migrate to tokens (optionally) and then migrate to XCSS.
|
|
108
107
|
|
|
109
108
|
```tsx
|
|
110
109
|
const MyComponent = styled.div`
|
|
@@ -128,9 +127,3 @@ const myComponentStyles = xcss({
|
|
|
128
127
|
|
|
129
128
|
const MyComponent = () => <Box xcss={myComponentStyles} />
|
|
130
129
|
```
|
|
131
|
-
|
|
132
|
-
## Get help
|
|
133
|
-
|
|
134
|
-
- Atlassians can reach out in [Slack](slack://channel?team=TFCUTJ0G5&id=CFJ9DU39U) for help with `xcss` migration.
|
|
135
|
-
- Other developers who need help with tokens or the `xcss` utility can post in the [public developer community](https://community.developer.atlassian.com/).
|
|
136
|
-
- For general help with the Atlassian Design System, [contact us](/resources/contact-us).
|
|
@@ -6,20 +6,20 @@ order: 0
|
|
|
6
6
|
|
|
7
7
|
import { MediaQueriesTable } from '@af/design-system-docs-ui';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
XCSS is an Atlassian Design System styling API that natively integrates with Atlassian's [design tokens](/tokens) and [primitives](/components/primitives).
|
|
10
10
|
|
|
11
|
-
The
|
|
11
|
+
The XCSS utility behaves similarly to the `css` utility in libraries like `styled-components`, `@compiled` or `@emotion`. If you've used these libraries, XCSS will feel familiar, with a few additional features and constraints.
|
|
12
12
|
|
|
13
13
|
Familiar features:
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
15
|
+
- XCSS generates a `className` that is applied to the components
|
|
16
|
+
- XCSS provides key-value pairs of CSS properties in an object format
|
|
17
|
+
- XCSS supports style precedence and conditional styles
|
|
18
18
|
|
|
19
19
|
Key differences:
|
|
20
20
|
|
|
21
|
-
-
|
|
22
|
-
-
|
|
21
|
+
- XCSS has type-safety that ensures token name usage for all CSS properties represented by design tokens.
|
|
22
|
+
- XCSS restricts nested selectors completely from usage
|
|
23
23
|
|
|
24
24
|
## Usage
|
|
25
25
|
|
|
@@ -55,7 +55,7 @@ It is important to note that styles generated from `xcss` cannot be applied dire
|
|
|
55
55
|
|
|
56
56
|
### Type safety
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
XCSS uses strongly-typed values generated from design token definitions, making it simpler to apply the right token to the right CSS property.
|
|
59
59
|
This is intended to be more ergonomic and intuitive, but also prevent the misapplication of tokens to the wrong properties.
|
|
60
60
|
|
|
61
61
|
Any [valid token name](/components/tokens/all-tokens) is available to be applied against its
|
|
@@ -75,7 +75,7 @@ const someStyles = xcss({
|
|
|
75
75
|
|
|
76
76
|
### Restricted nesting
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
XCSS is flexible enough to implement any design, but it does restrict the application of styles in one key way.
|
|
79
79
|
Selectors cannot be nested or target elements beyond the element on which styles are applied.
|
|
80
80
|
This restriction is intended to encourage better component encapsulation, reduce side-effects and make the codebase more resilient to change.
|
|
81
81
|
|
|
@@ -99,19 +99,20 @@ const someStyles = xcss({
|
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
These unsafe selectors will throw a type error if applied.
|
|
102
|
-
|
|
102
|
+
Find richer examples of how to use XCSS in the [XCSS examples](/components/primitives/xcss/examples).
|
|
103
103
|
|
|
104
104
|
### Media Queries
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
XCSS can create responsive layouts at predefined breakpoints that are consistent with the Atlassian Design System. To enable responsive behavior, XCSS exposes the following pre-defined breakpoints:
|
|
107
107
|
|
|
108
108
|
<MediaQueriesTable />
|
|
109
109
|
|
|
110
|
-
Media queries can be applied through keys
|
|
111
|
-
|
|
110
|
+
Media queries can be applied through keys imported from `@atlaskit/primitives/responsive`.
|
|
111
|
+
Find more in depth examples on how to enable responsive behavior in the [responsive documentation](/components/primitives/xcss/examples#responsiveness).
|
|
112
112
|
|
|
113
|
-
The objects defined at each breakpoint behave in much the same way as a normal
|
|
113
|
+
The objects defined at each breakpoint behave in much the same way as a normal XCSS object, and can apply responsiveness to any CSS.
|
|
114
114
|
The only limitation is that a media query can't contain another media query. This is to prevent arbitrary nesting.
|
|
115
|
+
|
|
115
116
|
Additionally, pseudo-selectors can't contain media queries. To use media queries and pseudos, the media query must contain the pseudo.
|
|
116
117
|
|
|
117
118
|
```
|
|
@@ -142,8 +143,8 @@ const someStyles = xcss({
|
|
|
142
143
|
});
|
|
143
144
|
```
|
|
144
145
|
|
|
145
|
-
##
|
|
146
|
+
## Related
|
|
146
147
|
|
|
147
|
-
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
148
|
+
- [Use box for a generic container with access to design tokens](/components/primitives/box/usage)
|
|
149
|
+
- [Manage horizontal layout using an inline component](/components/primitives/inline/usage)
|
|
150
|
+
- [Manage vertical layout using a stack component](/components/primitives/stack/usage)
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.uiTextStylesMap = exports.uiTextMap = exports.textColorStylesMap = exports.textColorMap = exports.surfaceColorStylesMap = exports.surfaceColorMap = exports.spaceStylesMap = exports.spaceMap = exports.shadowMap = exports.paddingStylesMap = exports.negativeSpaceMap = exports.lineHeightStylesMap = exports.lineHeightMap = exports.layerMap = exports.isSurfaceColorToken = exports.inverseColorMap = exports.fontWeightStylesMap = exports.fontWeightMap = exports.fontSizeStylesMap = exports.fontSizeMap = exports.fontFamilyStylesMap = exports.fontFamilyMap = exports.fillMap = exports.dimensionMap = exports.borderWidthMap = exports.borderRadiusMap = exports.borderColorMap = exports.bodyTextStylesMap = exports.bodyTextMap = exports.backgroundColorStylesMap = exports.backgroundColorMap = void 0;
|
|
7
|
+
exports.uiTextStylesMap = exports.uiTextMap = exports.textColorStylesMap = exports.textColorMap = exports.surfaceColorStylesMap = exports.surfaceColorMap = exports.spaceStylesMap = exports.spaceMap = exports.shadowMap = exports.paddingStylesMap = exports.opacityMap = exports.negativeSpaceMap = exports.lineHeightStylesMap = exports.lineHeightMap = exports.layerMap = exports.isSurfaceColorToken = exports.inverseColorMap = exports.fontWeightStylesMap = exports.fontWeightMap = exports.fontSizeStylesMap = exports.fontSizeMap = exports.fontFamilyStylesMap = exports.fontFamilyMap = exports.fillMap = exports.dimensionMap = exports.borderWidthMap = exports.borderRadiusMap = exports.borderColorMap = exports.bodyTextStylesMap = exports.bodyTextMap = exports.backgroundColorStylesMap = exports.backgroundColorMap = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _react = require("@emotion/react");
|
|
10
10
|
var _tokens = require("@atlaskit/tokens");
|
|
@@ -111,10 +111,45 @@ var inverseColorMap = exports.inverseColorMap = {
|
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
113
|
* THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
114
|
-
* @codegen <<SignedSource::
|
|
114
|
+
* @codegen <<SignedSource::8c10abde8168de6260b5aa120dd948bc>>
|
|
115
|
+
* @codegenId elevation
|
|
116
|
+
* @codegenCommand yarn workspace @atlaskit/primitives codegen-styles
|
|
117
|
+
* @codegenParams ["opacity", "shadow", "surface"]
|
|
118
|
+
* @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-light.tsx <<SignedSource::f1021f8d47ab63374e371ce18db72a1c>>
|
|
119
|
+
*/
|
|
120
|
+
var opacityMap = exports.opacityMap = {
|
|
121
|
+
'opacity.disabled': "var(--ds-opacity-disabled, 0.4)",
|
|
122
|
+
'opacity.loading': "var(--ds-opacity-loading, 0.2)"
|
|
123
|
+
};
|
|
124
|
+
var shadowMap = exports.shadowMap = {
|
|
125
|
+
'elevation.shadow.overflow': "var(--ds-shadow-overflow, 0px 0px 8px #091e423f, 0px 0px 1px #091e424f)",
|
|
126
|
+
'elevation.shadow.overflow.perimeter': "var(--ds-shadow-overflow-perimeter, #091e421f)",
|
|
127
|
+
'elevation.shadow.overflow.spread': "var(--ds-shadow-overflow-spread, #091e4229)",
|
|
128
|
+
'elevation.shadow.overlay': "var(--ds-shadow-overlay, 0px 8px 12px #091e423f, 0px 0px 1px #091e424f)",
|
|
129
|
+
'elevation.shadow.raised': "var(--ds-shadow-raised, 0px 1px 1px #091e423f, 0px 0px 1px #091e4221)"
|
|
130
|
+
};
|
|
131
|
+
var surfaceColorMap = exports.surfaceColorMap = {
|
|
132
|
+
'elevation.surface': "var(--ds-surface, #FFFFFF)",
|
|
133
|
+
'elevation.surface.hovered': "var(--ds-surface-hovered, #FAFBFC)",
|
|
134
|
+
'elevation.surface.pressed': "var(--ds-surface-pressed, #F4F5F7)",
|
|
135
|
+
'elevation.surface.overlay': "var(--ds-surface-overlay, #FFFFFF)",
|
|
136
|
+
'elevation.surface.overlay.hovered': "var(--ds-surface-overlay-hovered, #FAFBFC)",
|
|
137
|
+
'elevation.surface.overlay.pressed': "var(--ds-surface-overlay-pressed, #F4F5F7)",
|
|
138
|
+
'elevation.surface.raised': "var(--ds-surface-raised, #FFFFFF)",
|
|
139
|
+
'elevation.surface.raised.hovered': "var(--ds-surface-raised-hovered, #FAFBFC)",
|
|
140
|
+
'elevation.surface.raised.pressed': "var(--ds-surface-raised-pressed, #F4F5F7)",
|
|
141
|
+
'elevation.surface.sunken': "var(--ds-surface-sunken, #F4F5F7)"
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* @codegenEnd
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
149
|
+
* @codegen <<SignedSource::0f7982208166d5dae0e25517d29aeaef>>
|
|
115
150
|
* @codegenId colors
|
|
116
151
|
* @codegenCommand yarn workspace @atlaskit/primitives codegen-styles
|
|
117
|
-
* @codegenParams ["border", "background", "
|
|
152
|
+
* @codegenParams ["border", "background", "text", "fill"]
|
|
118
153
|
* @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-light.tsx <<SignedSource::f1021f8d47ab63374e371ce18db72a1c>>
|
|
119
154
|
*/
|
|
120
155
|
var borderColorMap = exports.borderColorMap = {
|
|
@@ -339,13 +374,6 @@ var backgroundColorMap = exports.backgroundColorMap = {
|
|
|
339
374
|
'elevation.surface.sunken': "var(--ds-surface-sunken, #F4F5F7)",
|
|
340
375
|
'utility.elevation.surface.current': "var(--ds-elevation-surface-current, #FFFFFF)"
|
|
341
376
|
};
|
|
342
|
-
var shadowMap = exports.shadowMap = {
|
|
343
|
-
'elevation.shadow.overflow': "var(--ds-shadow-overflow, 0px 0px 8px #091e423f, 0px 0px 1px #091e424f)",
|
|
344
|
-
'elevation.shadow.overflow.perimeter': "var(--ds-shadow-overflow-perimeter, #091e421f)",
|
|
345
|
-
'elevation.shadow.overflow.spread': "var(--ds-shadow-overflow-spread, #091e4229)",
|
|
346
|
-
'elevation.shadow.overlay': "var(--ds-shadow-overlay, 0px 8px 12px #091e423f, 0px 0px 1px #091e424f)",
|
|
347
|
-
'elevation.shadow.raised': "var(--ds-shadow-raised, 0px 1px 1px #091e423f, 0px 0px 1px #091e4221)"
|
|
348
|
-
};
|
|
349
377
|
var textColorMap = exports.textColorMap = {
|
|
350
378
|
'color.text': "var(--ds-text, #172B4D)",
|
|
351
379
|
'color.text.accent.lime': "var(--ds-text-accent-lime, #4C6B1F)",
|
|
@@ -408,18 +436,6 @@ var fillMap = exports.fillMap = {
|
|
|
408
436
|
'color.icon.information': "var(--ds-icon-information, #0747A6)",
|
|
409
437
|
'color.icon.subtle': "var(--ds-icon-subtle, #6B778C)"
|
|
410
438
|
};
|
|
411
|
-
var surfaceColorMap = exports.surfaceColorMap = {
|
|
412
|
-
'elevation.surface': "var(--ds-surface, #FFFFFF)",
|
|
413
|
-
'elevation.surface.hovered': "var(--ds-surface-hovered, #FAFBFC)",
|
|
414
|
-
'elevation.surface.pressed': "var(--ds-surface-pressed, #F4F5F7)",
|
|
415
|
-
'elevation.surface.overlay': "var(--ds-surface-overlay, #FFFFFF)",
|
|
416
|
-
'elevation.surface.overlay.hovered': "var(--ds-surface-overlay-hovered, #FAFBFC)",
|
|
417
|
-
'elevation.surface.overlay.pressed': "var(--ds-surface-overlay-pressed, #F4F5F7)",
|
|
418
|
-
'elevation.surface.raised': "var(--ds-surface-raised, #FFFFFF)",
|
|
419
|
-
'elevation.surface.raised.hovered': "var(--ds-surface-raised-hovered, #FAFBFC)",
|
|
420
|
-
'elevation.surface.raised.pressed': "var(--ds-surface-raised-pressed, #F4F5F7)",
|
|
421
|
-
'elevation.surface.sunken': "var(--ds-surface-sunken, #F4F5F7)"
|
|
422
|
-
};
|
|
423
439
|
/**
|
|
424
440
|
* @codegenEnd
|
|
425
441
|
*/
|