@atlaskit/primitives 0.9.0 → 0.9.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.
- package/CHANGELOG.md +12 -0
- package/README.md +6 -2
- package/box/package.json +2 -2
- package/constellation/box/code.mdx +6 -2
- package/constellation/box/usage.mdx +30 -0
- package/constellation/inline/code.mdx +1 -1
- package/constellation/inline/usage.mdx +36 -0
- package/constellation/overview/images/box-usage-example.png +0 -0
- package/constellation/overview/images/inline-usage-example.png +0 -0
- package/constellation/overview/images/stack-usage-example.png +0 -0
- package/constellation/overview/index.mdx +66 -0
- package/constellation/stack/code.mdx +1 -1
- package/constellation/stack/usage.mdx +31 -0
- package/constellation/xcss/examples.mdx +21 -0
- package/constellation/xcss/logo.png +0 -0
- package/constellation/xcss/migration.mdx +142 -0
- package/constellation/xcss/usage.mdx +115 -0
- package/dist/cjs/components/box.js +1 -1
- package/dist/cjs/components/inline.js +1 -1
- package/dist/cjs/components/internal/base-box.js +1 -1
- package/dist/cjs/components/stack.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/{internal → xcss}/style-maps.partial.js +13 -43
- package/dist/cjs/{internal → xcss}/xcss.js +38 -26
- package/dist/es2019/components/box.js +1 -1
- package/dist/es2019/components/inline.js +1 -1
- package/dist/es2019/components/internal/base-box.js +1 -1
- package/dist/es2019/components/stack.js +1 -1
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/{internal → xcss}/style-maps.partial.js +12 -40
- package/dist/es2019/{internal → xcss}/xcss.js +38 -25
- package/dist/esm/components/box.js +1 -1
- package/dist/esm/components/inline.js +1 -1
- package/dist/esm/components/internal/base-box.js +1 -1
- package/dist/esm/components/stack.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/esm/{internal → xcss}/style-maps.partial.js +12 -40
- package/dist/esm/{internal → xcss}/xcss.js +39 -27
- package/dist/types/components/box.d.ts +2 -2
- package/dist/types/components/inline.d.ts +7 -7
- package/dist/types/components/internal/base-box.d.ts +15 -14
- package/dist/types/components/stack.d.ts +6 -6
- package/dist/types/components/types.d.ts +3 -3
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/helpers/responsive/types.d.ts +4 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/{internal → xcss}/style-maps.partial.d.ts +81 -130
- package/dist/types/xcss/xcss.d.ts +57 -0
- package/extract-react-types/box-props.tsx +95 -0
- package/extract-react-types/inline-props.tsx +86 -1
- package/extract-react-types/stack-props.tsx +70 -1
- package/inline/package.json +2 -2
- package/package.json +25 -8
- package/report.api.md +94 -354
- package/responsive/package.json +2 -2
- package/scripts/codegen-file-templates/dimensions.tsx +17 -16
- package/scripts/codegen-styles.tsx +2 -2
- package/scripts/spacing-codegen-template.tsx +24 -91
- package/stack/package.json +2 -2
- package/tmp/api-report-tmp.d.ts +649 -0
- package/constellation/overview/examples.mdx +0 -7
- package/dist/cjs/components/internal/extract-react-types/inline-props.js +0 -7
- package/dist/cjs/components/internal/extract-react-types/stack-props.js +0 -7
- package/dist/es2019/components/internal/extract-react-types/inline-props.js +0 -1
- package/dist/es2019/components/internal/extract-react-types/stack-props.js +0 -1
- package/dist/esm/components/internal/extract-react-types/inline-props.js +0 -1
- package/dist/esm/components/internal/extract-react-types/stack-props.js +0 -1
- package/dist/types/components/internal/extract-react-types/inline-props.d.ts +0 -2
- package/dist/types/components/internal/extract-react-types/stack-props.d.ts +0 -2
- package/dist/types/internal/xcss.d.ts +0 -50
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/primitives
|
|
2
2
|
|
|
3
|
+
## 0.9.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`41fae2c6f68`](https://bitbucket.org/atlassian/atlassian-frontend/commits/41fae2c6f68) - Upgrade Typescript from `4.5.5` to `4.9.5`
|
|
8
|
+
|
|
9
|
+
## 0.9.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`5a9e73494eb`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5a9e73494eb) - Updates to internal documentation.
|
|
14
|
+
|
|
3
15
|
## 0.9.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -4,6 +4,10 @@ Primitives are token-backed low-level building blocks.
|
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Detailed docs and example usage can be found at:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- [Overview](https://staging.atlassian.design/components/primitives/overview)
|
|
10
|
+
- [Box](https://staging.atlassian.design/components/primitives/box)
|
|
11
|
+
- [Inline](https://staging.atlassian.design/components/primitives/inline)
|
|
12
|
+
- [Stack](https://staging.atlassian.design/components/primitives/stack)
|
|
13
|
+
- [xCSS](https://staging.atlassian.design/components/primitives/xcss)
|
package/box/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Box
|
|
3
|
-
description:
|
|
3
|
+
description: Box is a primitive component that leverages the foundations of the Atlassian Design System.
|
|
4
4
|
order: 1
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import BoxProps from '!!extract-react-types-loader!../../extract-react-types/box-props'
|
|
8
|
+
|
|
9
|
+
## Props
|
|
10
|
+
|
|
11
|
+
<PropsTable heading="" props={BoxProps} />
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Box
|
|
3
|
+
description: A box is a primitive component that acts as a generic container, and provides managed access to design tokens.
|
|
4
|
+
order: 2
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Use box to compose layouts with the valid spacing and background colors. A `Box` is a generic container with convenient and managed access to design tokens, and built-in guidance for the best practices of the Atlassian Design System.
|
|
8
|
+
|
|
9
|
+
A `Box` is primarily a containment element, with visual props that affect the whitespace available to child elements.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Use `Box`
|
|
13
|
+
Display behavior is set by using the available props or using `xcss`. Makers can make design decisions for `Box` by setting:
|
|
14
|
+
|
|
15
|
+
- `padding`
|
|
16
|
+
- `paddingInline`
|
|
17
|
+
- `paddingInlineStart`
|
|
18
|
+
- `paddingInlineEnd`
|
|
19
|
+
- `paddingBlock`
|
|
20
|
+
- `paddingBlockStart`
|
|
21
|
+
- `paddingBlockEnd`
|
|
22
|
+
- `backgroundColor`
|
|
23
|
+
|
|
24
|
+
To identify usages of `Box` in a given design, look for where a UI element (could be as small as the parent of a button or as a big as the wrapper of an entire section) will receive some visual styles applied to a container.
|
|
25
|
+
|
|
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
|
+
Related
|
|
29
|
+
- [Learn more about the Inline primitive](/components/primitives/inline/usage)
|
|
30
|
+
- [Learn more about the Stack primitive](/components/primitives/stack/usage)
|
|
@@ -4,7 +4,7 @@ description: Inline is a primitive component based on flexbox that manages the h
|
|
|
4
4
|
order: 1
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import InlineProps from '!!extract-react-types-loader!../../
|
|
7
|
+
import InlineProps from '!!extract-react-types-loader!../../extract-react-types/inline-props'
|
|
8
8
|
|
|
9
9
|
## Props
|
|
10
10
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Inline
|
|
3
|
+
description: An Inline is a primitive component that is responsible for the horizontal layout of its child elements.
|
|
4
|
+
order: 2
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Primitive components are designed to act as building blocks for composing a user experience. An Inline primitive should be used when you want to layout UI elements horizontally, and make use of the built-in design guidance from the Atlassian Design System.
|
|
8
|
+
|
|
9
|
+
Inline primitives work as you might expect, aligning content horizontally across a page or layout, as a container that decides the horizontal layout of its children. Inline 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. Inline should be used purely for visual alignment, and should have no opinions about the functionality of its children.
|
|
10
|
+
|
|
11
|
+
In its simplest form, `Inline` operates like a flexbox row, however adds the built in design token support and guidance.
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
<Inline space="space.100" alignInline="center" alignBlock="start">
|
|
15
|
+
...
|
|
16
|
+
</Inline>
|
|
17
|
+
```
|
|
18
|
+
It also has a flex-direction: row; but that’s the default, so not explicitly applied.
|
|
19
|
+
|
|
20
|
+
## Use `Inline`
|
|
21
|
+
The purpose of an Inline is primarily as a container element controlling how child components are displayed and positioned horizontally. Inline should be used any time you wish to layout elements or components horizontally.
|
|
22
|
+
|
|
23
|
+
The various Inline props can then be used to customize the spacing and styling on any child elements. These include:
|
|
24
|
+
|
|
25
|
+
- `alignBlock`
|
|
26
|
+
- `alignInline`
|
|
27
|
+
- `shouldWrap`
|
|
28
|
+
- `spread`
|
|
29
|
+
- `grow`
|
|
30
|
+
- `space`
|
|
31
|
+
- `rowSpace`
|
|
32
|
+
- `separator`
|
|
33
|
+
|
|
34
|
+
## Related
|
|
35
|
+
- [Learn more about the Box primitive](/components/primitives/box/usage)
|
|
36
|
+
- [Learn more about the Stack primitive](/components/primitives/stack/usage)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Primitives
|
|
3
|
+
description: Primitives are composable components that solve common layout problems.
|
|
4
|
+
|
|
5
|
+
order: 1
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
import SectionMessage from '@atlaskit/section-message';
|
|
9
|
+
import Image from '@atlaskit/image';
|
|
10
|
+
|
|
11
|
+
import boxUsageExample from './images/box-usage-example.png';
|
|
12
|
+
import inlineUsageExample from './images/inline-usage-example.png';
|
|
13
|
+
import stackUsageExample from './images/stack-usage-example.png';
|
|
14
|
+
|
|
15
|
+
<SectionMessage title="This is a preview of our new primitive components." appearance="warning">
|
|
16
|
+
Expect frequent changes as we iterate over the coming months. For early access and release updates for Atlassian employees, see details.
|
|
17
|
+
</SectionMessage>
|
|
18
|
+
|
|
19
|
+
Primitive components are a new type of component for layouts and placement of elements. They act as building blocks to compose different parts of the user experience, from the smallest design decisions (for example, the spacing around an icon) to larger layout decisions (for example, how a page is structured).
|
|
20
|
+
|
|
21
|
+
Primitives are designed to work hand in hand with design tokens, to provide opinionated solutions for common low-level design decisions that engineers often have to make. They are designed to reduce cognitive overhead for engineers by providing guardrails around what is recommended within our design system.
|
|
22
|
+
|
|
23
|
+
A primitive component is a pre-built solution in that they will only accept values that are valid in the Atlassian Design System, and help to implement common layout patterns. This reduces the need to look up documentation and write custom CSS.
|
|
24
|
+
|
|
25
|
+
## Available Primitives
|
|
26
|
+
|
|
27
|
+
Each primitive is designed to have a single responsibility, and it should be immediately clear where each primitive should be used. However, they are also flexible enough that they should be able to be used to compose complex designs not otherwise covered in the Design Systems.
|
|
28
|
+
|
|
29
|
+
Currently, three primitive components are available for use in Closed Beta they are Box, Inline and Stack. These were chosen because a large amount of layout problems can be reduced to laying out content:
|
|
30
|
+
- in a container (see [box](/components/primitives/box))
|
|
31
|
+
- horizontally (see [inline](/components/primitives/inline))
|
|
32
|
+
- vertically (see [stack](/components/primitives/stack))
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
To install primitive components, add @atlaskit/primitives as a dependency on your project:
|
|
37
|
+
```bash
|
|
38
|
+
$ yarn add @atlaskit/primitives
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Using Primitives
|
|
42
|
+
|
|
43
|
+
Use primitives for general layout styles for components. Primitives are not currently available in Figma, so the first step in implementing primitive components is identifying where they might fit in a given design. This involves breaking down a design into its core layout components to as granular level as is useful.
|
|
44
|
+
|
|
45
|
+
<SectionMessage appearance="warning">
|
|
46
|
+
Primitives could be skipped where absolute DOM control is required or very specific styling values are needed, however, this approach is more likely to produce visual elements that fail to adhere to the guidelines of the Atlassian Design System.
|
|
47
|
+
</SectionMessage>
|
|
48
|
+
|
|
49
|
+
You might like to think first about breaking down a page into Box containers, identifying larger pieces of a design that function in a similar manner or fulfill a singular purpose in a layout and grouping them together under a Box.
|
|
50
|
+
|
|
51
|
+
<Image src={boxUsageExample} />
|
|
52
|
+
|
|
53
|
+
The behavior within and around these boxes can then be broken down into their horizontal Inline and vertical Stack components.
|
|
54
|
+
|
|
55
|
+
<SectionMessage>
|
|
56
|
+
The ESLint rule use-primitives offers suggestions for possible primitives in a layout.
|
|
57
|
+
</SectionMessage>
|
|
58
|
+
|
|
59
|
+
<Image src={inlineUsageExample} />
|
|
60
|
+
<Image src={stackUsageExample} />
|
|
61
|
+
|
|
62
|
+
## Related
|
|
63
|
+
|
|
64
|
+
- [Learn more about the Box primitive](/components/primitives/box/usage)
|
|
65
|
+
- [Learn more about the Inline primitive](/components/primitives/inline/usage)
|
|
66
|
+
- [Learn more about the Stack primitive](/components/primitives/stack/usage)
|
|
@@ -4,7 +4,7 @@ description: Stack is a primitive component based on flexbox that manages the ve
|
|
|
4
4
|
order: 1
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import StackProps from '!!extract-react-types-loader!../../
|
|
7
|
+
import StackProps from '!!extract-react-types-loader!../../extract-react-types/stack-props'
|
|
8
8
|
|
|
9
9
|
## Props
|
|
10
10
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Stack
|
|
3
|
+
description: A Stack is a primitive component that is responsible for the vertical layout of its child elements.
|
|
4
|
+
order: 2
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Primitive components are designed to act as building blocks for composing a user experience. A `Stack` primitive should be used when you want to layout UI elements vertically, and make use of the built-in design guidance from the Atlassian Design System.
|
|
8
|
+
|
|
9
|
+
`Stack` primitives work by aligning content vertically on a page or layout, 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` should be used purely for visual alignment, and should have no opinions about the functionality of its children.
|
|
10
|
+
|
|
11
|
+
In its simplest form, `Stack` operates like a flexbox column, however adds the built in design token support and guidance.
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
<Stack space="space.100" alignInline="center" alignBlock="start">
|
|
15
|
+
...
|
|
16
|
+
</Stack>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Use `Stack`
|
|
20
|
+
The purpose of a `Stack` is primarily as a container element controlling how content is displayed and aligned vertically. `Stack` should be used any time you wish to layout elements or components vertically.
|
|
21
|
+
|
|
22
|
+
The various `Stack` props can then be used to customize the spacing and styling on any child elements. These include:
|
|
23
|
+
- `alignBlock`
|
|
24
|
+
- `alignInline`
|
|
25
|
+
- `spread`
|
|
26
|
+
- `grow`
|
|
27
|
+
- `space`
|
|
28
|
+
|
|
29
|
+
## Related
|
|
30
|
+
- [Learn more about the Box primitive](/primitives/box/usage)
|
|
31
|
+
- [Learn more about the Stack primitive](/primitives/box/usage)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: xCSS
|
|
3
|
+
description: xCSS is a safer, tokens-first approach to CSS-in-JS.
|
|
4
|
+
order: 1
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
import xcssBasic from '../../examples/constellation/xcss/basic';
|
|
8
|
+
import xcssInteractive from '../../examples/constellation/xcss/interactivity';
|
|
9
|
+
|
|
10
|
+
## Basic
|
|
11
|
+
|
|
12
|
+
`xcss` can be used to pull together different types of interactions and UI in a safer more composable way.
|
|
13
|
+
|
|
14
|
+
<Example Component={xcssBasic} packageName="@atlaskit/primitives/xcss" />
|
|
15
|
+
|
|
16
|
+
## Interactivity
|
|
17
|
+
|
|
18
|
+
To enable interactivity you can lean on familiar selectors like `:hover` and `:focus-visible`.
|
|
19
|
+
|
|
20
|
+
<Example Component={xcssInteractive} packageName="@atlaskit/primitives/xcss" />
|
|
21
|
+
|
|
Binary file
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Migrating your app to xCSS
|
|
3
|
+
description: xCSS is a safer, tokens-first approach to CSS-in-JS.
|
|
4
|
+
order: 2
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Summary of changes
|
|
8
|
+
|
|
9
|
+
### Changes for developers
|
|
10
|
+
|
|
11
|
+
There are two key changes to be mindful of when migrating to use `xcss`.
|
|
12
|
+
The first is needing to update callsites to remove any nested styles and
|
|
13
|
+
tokenised values.
|
|
14
|
+
|
|
15
|
+
```diff
|
|
16
|
+
- import { css } from '@emotion/react';
|
|
17
|
+
+ import { xcss } from '@atlaskit/primitives';
|
|
18
|
+
|
|
19
|
+
- const someStyles = css({
|
|
20
|
+
+ const someStyles = xcss({
|
|
21
|
+
// token based properties will no longer need to be wrapped
|
|
22
|
+
- padding: token('space.100'),
|
|
23
|
+
+ padding: 'space.100'
|
|
24
|
+
// no change is required for non-tokenised values
|
|
25
|
+
transform: 'scale(2)'
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The second is that for the `xcss` function to be applied correctly it must be applied on a
|
|
30
|
+
component with an `xcss` JSXAttribute. By default this won't work with the `css` or `className`
|
|
31
|
+
JSXAttributes - so be aware if you're not seeing your styles appear.
|
|
32
|
+
|
|
33
|
+
```diff
|
|
34
|
+
- <div css={someStyles} />
|
|
35
|
+
+ <Box xcss={someStyles} />
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
#### Changing the way you express styles
|
|
40
|
+
|
|
41
|
+
Why are nested selectors a problem? A key philosophy of `xcss` is encouraging more deterministic style application. This restriction is designed to eliminate side-effects and
|
|
42
|
+
encourage component encapsulation. Consider the below example:
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
const myComponentStyles = css({
|
|
46
|
+
'> *': {
|
|
47
|
+
color: 'color.text.danger',
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const MyComponent = () => (
|
|
52
|
+
<div css={myComponentStyles}>
|
|
53
|
+
<p>Text here</p>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Here the component is applying styles that are implicity meant for the text wrapped in the `p` below.
|
|
59
|
+
In this simple example, it may seem okay, desirable even, but cases like these often occur across module or component boundaries.
|
|
60
|
+
|
|
61
|
+
This makes the visibility of these dependencies harder to capture or reason about.
|
|
62
|
+
Styles that are inherited or indirectly apply make a UI brittle to change and hard to evolve.
|
|
63
|
+
Instead, if the same styles are applied directly on the affected element we can minimize and in some cases completely eliminate this problem.
|
|
64
|
+
|
|
65
|
+
```diff
|
|
66
|
+
const myTextStyles = xcss({
|
|
67
|
+
- '> *': {
|
|
68
|
+
color: 'color.text.danger',
|
|
69
|
+
- }
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const MyComponent = () => (
|
|
73
|
+
- <div xcss={myComponentStyles}>
|
|
74
|
+
+ <Box
|
|
75
|
+
+ <Text xcss={myTextStyles}>Text here</Text>
|
|
76
|
+
</Box>
|
|
77
|
+
);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
There are likely to be cases where nesting is the only option. While not desirable, this is fine as long as it's considered
|
|
81
|
+
a last resort.
|
|
82
|
+
|
|
83
|
+
### FAQ
|
|
84
|
+
|
|
85
|
+
Overall migration to `xcss` is fairly simple for the majority of cases. Here are some common strategies for migrations.
|
|
86
|
+
|
|
87
|
+
#### Non-tokenised values
|
|
88
|
+
|
|
89
|
+
If you're yet to migrate to tokens, you have two options. You can migrate to tokens first and then on a second pass
|
|
90
|
+
migrate to `xcss` or you can make the jump directly.
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
const someStyles = css({
|
|
94
|
+
color: 'red',
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// ->>> Optional middle step
|
|
98
|
+
const someStyles = css({
|
|
99
|
+
color: token('color.text.danger'),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// ->>> The final state
|
|
103
|
+
const someStyles = xcss({
|
|
104
|
+
color: 'color.text.danger',
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Moving from the `styled` API
|
|
109
|
+
|
|
110
|
+
If you're currently using the `styled` API there are a few steps required to migration.
|
|
111
|
+
The safest approach is to a step change to use object styles, migrate to tokens (optionally)
|
|
112
|
+
and then migrate to `xcss`.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
const MyComponent = styled.div`
|
|
116
|
+
color: red;
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
// ->>> move to object styles
|
|
120
|
+
const MyComponent = styled.div({
|
|
121
|
+
color: 'red';
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// ->>> move to tokens
|
|
125
|
+
const MyComponent = styled.div({
|
|
126
|
+
color: token('color.text.danger'),
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// ->>> move to Box
|
|
130
|
+
const myComponentStyles = xcss({
|
|
131
|
+
color: 'color.text.danger',
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const MyComponent = () => <Box xcss={myComponentStyles} />
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## Get help
|
|
139
|
+
|
|
140
|
+
* Atlassians can reach out in [Slack](slack://channel?team=TFCUTJ0G5&id=CFJ9DU39U) for help with `xcss` migration.
|
|
141
|
+
* Other developers who need help with tokens or the `xcss` utility can post in the [public developer community](https://community.developer.atlassian.com/).
|
|
142
|
+
* For general help with the Atlassian Design System, [contact us](/resources/contact-us).
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: xCSS
|
|
3
|
+
description: xCSS is a safer, tokens-first approach to CSS-in-JS.
|
|
4
|
+
order: 0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
`xcss` is an Atlassian Design System styling API designed to natively integrate with
|
|
10
|
+
Atlassian's [design tokens](/tokens) and [primitives](/components/primitives) in a safer, more resilient and evolvable way.
|
|
11
|
+
|
|
12
|
+
The `xcss` utility behaves similarly to the `css` utility in libraries
|
|
13
|
+
like `styled-components`, `@compiled` or `@emotion` - so if you've used those libraries before
|
|
14
|
+
it will feel very familiar, with a few additional features and some constraints.
|
|
15
|
+
|
|
16
|
+
Features that will feel familiar:
|
|
17
|
+
|
|
18
|
+
* `xcss` will generate a `className` to be applied on your components
|
|
19
|
+
* `xcss` will provide key-value pairs of CSS properties in an object format
|
|
20
|
+
* `xcss` supports style precedence and conditional styles
|
|
21
|
+
|
|
22
|
+
But it also has a few key differences.
|
|
23
|
+
|
|
24
|
+
* `xcss` has type-safety that uses token names for all CSS properties that are represented by design tokens.
|
|
25
|
+
* `xcss` restricts nested selectors completely from usage.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
To get started, import the function from `@atlaskit/primitives` and create a style:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { xcss } from '@atlaskit/primitives';
|
|
33
|
+
|
|
34
|
+
// Creates a basic style
|
|
35
|
+
const someStyles = xcss({
|
|
36
|
+
display: 'block',
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Apply this style to a component through the `xcss` prop:
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { Box, xcss } from '@atlaskit/primitives';
|
|
44
|
+
|
|
45
|
+
// Creates a basic style
|
|
46
|
+
const someStyles = xcss({
|
|
47
|
+
display: 'block',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const MyBox = () => {
|
|
51
|
+
return <Box xcss={someStyles} />
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The prop and the `xcss` function are direct complements and are meant
|
|
56
|
+
to be used together. Note: styles generated from `xcss` cannot be applied directly
|
|
57
|
+
to the `className` property or `css` as they are with other CSS-in-JS libraries.
|
|
58
|
+
|
|
59
|
+
### Type safety
|
|
60
|
+
|
|
61
|
+
`xcss` uses strongly-typed values generated from design token
|
|
62
|
+
definitions to make it simpler to apply the right token for the right CSS property.
|
|
63
|
+
This is intended to be more ergonomic and intuitive but also prevent the misapplication of tokens
|
|
64
|
+
to the wrong properties.
|
|
65
|
+
|
|
66
|
+
Any [valid token name](/components/tokens/all-tokens) is available to be applied against its
|
|
67
|
+
matching CSS property. For example, the token name `space.200`
|
|
68
|
+
is a valid value below for `padding` but will not appear
|
|
69
|
+
as a color, or a font.
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import { xcss } from '@atlaskit/primitives';
|
|
73
|
+
|
|
74
|
+
const someStyles = xcss({
|
|
75
|
+
padding: 'space.200', // <--- works
|
|
76
|
+
color: 'space.200', // <--- invalid and will error
|
|
77
|
+
borderRadius: 'radius.100' // <--- also valid
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Restricted nesting
|
|
82
|
+
|
|
83
|
+
`xcss` is meant to be flexible enough for you to implement any design but it does
|
|
84
|
+
restrict the application of styles in one key way. Selectors cannot be
|
|
85
|
+
nested or target elements beyond the element on which styles are applied.
|
|
86
|
+
This restriction is intended to encourage better component encapsulation, reduce side-effects and make
|
|
87
|
+
your codebase more resilient to change.
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import { xcss } from '@atlaskit/primitives';
|
|
91
|
+
|
|
92
|
+
const someStyles = xcss({
|
|
93
|
+
':hover': {
|
|
94
|
+
transform: 'scale(1)' // this is okay
|
|
95
|
+
},
|
|
96
|
+
// This is not okay as this selector affects any nested div in
|
|
97
|
+
// the component tree.
|
|
98
|
+
'div:hover': {
|
|
99
|
+
transform: 'scale(1)'
|
|
100
|
+
},
|
|
101
|
+
// Neither is this
|
|
102
|
+
'> * > div:hover': {
|
|
103
|
+
transform: 'scale(1)'
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
These unsafe selectors will throw a type error if applied.
|
|
109
|
+
For richer examples of how to use `xcss` please see our [documentation here](/components/primitives/xcss/examples).
|
|
110
|
+
|
|
111
|
+
## Get help
|
|
112
|
+
|
|
113
|
+
* Atlassians can reach out in [Slack](slack://channel?team=TFCUTJ0G5&id=CFJ9DU39U) for help with `xcss` migration.
|
|
114
|
+
* Other developers who need help with tokens or the `xcss` utility can post in the [public developer community](https://community.developer.atlassian.com/).
|
|
115
|
+
* For general help with the Atlassian Design System, [contact us](/resources/contact-us).
|
|
@@ -9,7 +9,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
9
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
10
|
var _react = require("react");
|
|
11
11
|
var _react2 = require("@emotion/react");
|
|
12
|
-
var _xcss = require("../
|
|
12
|
+
var _xcss = require("../xcss/xcss");
|
|
13
13
|
var _baseBox = require("./internal/base-box");
|
|
14
14
|
var _excluded = ["as", "children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "style", "testId", "xcss"],
|
|
15
15
|
_excluded2 = ["className"];
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _react2 = require("@emotion/react");
|
|
9
|
-
var _styleMaps = require("../
|
|
9
|
+
var _styleMaps = require("../xcss/style-maps.partial");
|
|
10
10
|
/* eslint-disable @repo/internal/styles/no-exported-styles */
|
|
11
11
|
/** @jsx jsx */
|
|
12
12
|
|
|
@@ -9,7 +9,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
9
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
10
|
var _react = require("react");
|
|
11
11
|
var _react2 = require("@emotion/react");
|
|
12
|
-
var _styleMaps = require("../../
|
|
12
|
+
var _styleMaps = require("../../xcss/style-maps.partial");
|
|
13
13
|
var _excluded = ["as", "className", "children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "style", "testId"];
|
|
14
14
|
/* eslint-disable @repo/internal/styles/no-exported-styles */
|
|
15
15
|
/** @jsx jsx */
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _react2 = require("@emotion/react");
|
|
9
|
-
var _styleMaps = require("../
|
|
9
|
+
var _styleMaps = require("../xcss/style-maps.partial");
|
|
10
10
|
/* eslint-disable @repo/internal/styles/no-exported-styles */
|
|
11
11
|
/** @jsx jsx */
|
|
12
12
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -30,5 +30,5 @@ Object.defineProperty(exports, "xcss", {
|
|
|
30
30
|
});
|
|
31
31
|
var _box = _interopRequireDefault(require("./components/box"));
|
|
32
32
|
var _inline = _interopRequireDefault(require("./components/inline"));
|
|
33
|
-
var _xcss = require("./
|
|
33
|
+
var _xcss = require("./xcss/xcss");
|
|
34
34
|
var _stack = _interopRequireDefault(require("./components/stack"));
|
package/dist/cjs/version.json
CHANGED