Skip to content

Commit 1a2f813

Browse files
authored
Merge pull request #3 from vtex-components/feature/as
Allow Button to use reakit's composition
2 parents 3e22d0d + c5e17f5 commit 1a2f813

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ yarn add reakit theme-ui
2020

2121
```tsx
2222
import React from 'react'
23-
import Button from '@vtex-component/button'
23+
import Button from '@vtex-components/button'
2424

2525
function Example() {
2626
return <Button>Button Label</Button>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vtex-components/button",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "VTEX button component",
55
"author": "vtex",
66
"license": "MIT",

src/Button.stories.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import { ThemeProvider } from 'theme-ui'
33
import { withA11y } from '@storybook/addon-a11y'
44
import { withKnobs, text, color, boolean } from '@storybook/addon-knobs'
5+
import { Checkbox, useCheckboxState } from 'reakit'
56

67
import Button from '.'
78

@@ -45,6 +46,26 @@ export function TheSXProp() {
4546
)
4647
}
4748

49+
export function TheAsProp() {
50+
const checkbox = useCheckboxState()
51+
52+
return (
53+
<ThemeProvider
54+
theme={{
55+
colors: {
56+
background: '#FFFFFF',
57+
primary: '#2F323A',
58+
secondary: '#4F5D75',
59+
},
60+
}}
61+
>
62+
<Checkbox {...checkbox} as={Button}>
63+
{checkbox.state ? '😄 Happy' : '😞 Sad'}
64+
</Checkbox>
65+
</ThemeProvider>
66+
)
67+
}
68+
4869
export function Theming() {
4970
const theme = {
5071
colors: {

src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77

88
type Props = A11yProps & ThemeAwareProps
99

10-
function Button(props: Props, ref: Ref<HTMLButtonElement>) {
11-
return <A11yButton {...props} ref={ref} as={ThemeAwareButton} />
10+
function Button({ as, ...props }: Props, ref: Ref<HTMLButtonElement>) {
11+
return <A11yButton {...props} ref={ref} as={as ?? ThemeAwareButton} />
1212
}
1313

1414
export { A11yProps, ThemeAwareProps }

0 commit comments

Comments
 (0)