UNPKG

3.54 kBTypeScriptView Raw
1import { code, md } from '@kalamazoo/docs';
2
3export default md`
4
5## v11 to v12
6
7### ⚡️ Highlights
8- **New theming API** - Button now supports the new Atlaskit theming API, which allows for powerful custom theming of Buttons and
9 its internal components.
10- **Speed improvements** - Button has been re-written from the ground up - on heavy-load benchmarks, Button is twice as fast
11 (taking 48% of the time to load).
12- **Emotion support** - Button is now built using Emotion 10! This is part of a wider push
13 for Emotion across all Atlaskit components.
14
15### 💥 Breaking Changes:
16- The old theming API is no longer supported.
17- Styling a Button using Styled Components is no longer supported.
18- Custom components will need refs forwarded via \`React.forwardRef()\`.
19- Camel-case ARIA props have been removed in favour for standard HTML aria-* attributes.
20
21<br/>
22
23---
24
25### Theming
26
27Button now supports the updated Theming API. Custom theming functions have access to all of Button's props, as well as the to the original ADG theme - meaning that the custom theme can
28change appearance based on different props, and even ignore the ADG styling completely. Custom
29themes can modify any CSS prop on the button body, the internal icons, or the loading spinner.
30
31For more details on building a custom Button theme, see the Theming Guide.
32
33#### Dark Mode support
34
35In \`v11\` we would add _dark mode_ to a button as follows:
36
37${code`<Button theme="dark">Button</Button>`}
38
39The above code could be written in \`v12\` as:
40
41${code`
42<Button theme={(theme, props) => theme({ ...props, mode: 'dark' })}
43 Button
44</Button>
45`}
46
47#### Styled-components support
48In \`v11\`, Button could be styled using styled-components' \`styled\` function:
49
50${code`
51import styled from 'styled-components'
52
53const CustomButton = styled(Button)\`
54 background-color: red
55\`)
56`}
57
58With the shift to Emotion in \`v12\`, Emotion’s own \‘styled\’ function is a functional drop-in replacement - however this is not explicitly supported and we recommend using the new theming API in its place.
59
60We recommend viewing the [Theming example](https://atlaskit.atlassian.com/packages/core/button/example/CustomTheme) for more information on how to use the new theming API with Button.
61
62<br/>
63
64---
65
66### Custom component
67If you need to work with refs in a custom component, you'll need to make sure to forward on refs yourself using \`React.forwardRef()\`. A typical use case would look like this:
68
69${code`
70const CustomButton = React.forwardRef<HTMLElement, React.AllHTMLAttributes<HTMLElement>>(
71 (props, ref) => <button {...props} ref={ref} />
72);
73
74<Button component={CustomButton} />
75`}
76
77<br/>
78
79---
80
81### ARIA attributes
82
83ARIA attributes for Button now use kebab-case standard in React. The old attributes have been deprecated.
84
85In \`v11\` we would use ARIA props as follows:
86
87${code`
88<Button
89 ariaExpanded
90 ariaHaspopup
91 ariaLabel="special button"
92>
93 Aria Button
94</Button>
95`}
96
97The above code could be written in \`v12\` as:
98
99${code`
100<Button
101 aria-expanded
102 aria-haspopup
103 aria-label="special button"
104>
105 Aria Button
106</Button>
107`}
108
109<br/>
110
111---
112
113### ⏫ Props updated
114- theme: Returns a function containing two args; the current ADG theme and props
115- component: Make sure to forward refs using \`React.forwardRef()\`.
116
117### 🙅‍ Props removed
118- ariaControls: Please use **aria-controls** prop instead
119- ariaExpanded: Please use **aria-expanded** prop instead
120- ariaLabel: Please use **aria-label** prop instead
121- ariaHaspopup: Please use **aria-haspopup** prop instead
122`;