Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit 3b2c8ed

Browse files
committed
feat: add outline variant on buttons
1 parent 14e638c commit 3b2c8ed

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

packages/shared/core/Button.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { darken } from 'polished'
2+
import { darken, transparentize } from 'polished'
33
import { Button as ReakitButton } from 'reakit/Button'
44
import { th, system } from '@xstyled/system'
55
import { node, bool, oneOf, string, oneOfType } from 'prop-desc'
@@ -17,7 +17,7 @@ import {
1717

1818
export const Button = createComponent({
1919
name: 'Button',
20-
render: props => {
20+
render: ({ variant, outline, ...props }) => {
2121
return <ReakitButton {...props} />
2222
},
2323
theme: [
@@ -32,6 +32,7 @@ export const Button = createComponent({
3232
},
3333
components: {
3434
Button: p => {
35+
const { outline } = p
3536
const scale = p.scale || 'base'
3637
const baseColor =
3738
p.variant === null ? null : th.color(p.variant || 'primary')(p)
@@ -61,6 +62,7 @@ export const Button = createComponent({
6162
}
6263
6364
${baseColor &&
65+
!outline &&
6466
css`
6567
color: ${colorYik(baseColor)(p)};
6668
background-color: ${baseColor};
@@ -76,6 +78,27 @@ export const Button = createComponent({
7678
}
7779
`(p)}
7880
81+
${baseColor &&
82+
outline &&
83+
css`
84+
color: ${darken(0.05, baseColor)};
85+
background-color: transparent;
86+
border: 1;
87+
border-color: ${baseColor};
88+
89+
&:focus {
90+
${p.theme.mixins.controlFocus(baseColor)(p)};
91+
border-color: ${baseColor};
92+
}
93+
94+
&:not(:disabled):hover,
95+
&:not(:disabled):active {
96+
color: ${darken(0.1, baseColor)};
97+
border-color: ${darken(0.05, baseColor)};
98+
background-color: ${transparentize(0.8, baseColor)};
99+
}
100+
`}
101+
79102
&& {
80103
${system(p)}
81104
}

website/src/pages/docs/button.mdx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,55 @@ function Example() {
3838
render(<Example />)
3939
```
4040

41+
## Outline
42+
43+
Add `outline` prop to use the outline variant of buttons.
44+
45+
```jsx live noInline
46+
import React from 'react'
47+
import { Button, Boxer } from '@smooth-ui/core-sc'
48+
49+
function Example() {
50+
return (
51+
<Boxer my={10}>
52+
<Button outline>Default (primary)</Button>
53+
<Button outline variant="primary">
54+
Primary
55+
</Button>
56+
<Button outline variant="secondary">
57+
Secondary
58+
</Button>
59+
<Button outline variant="success">
60+
Success
61+
</Button>
62+
<Button outline variant="danger">
63+
Danger
64+
</Button>
65+
<Button outline variant="warning">
66+
Warning
67+
</Button>
68+
<Button outline variant="info">
69+
Info
70+
</Button>
71+
<Button outline variant="light">
72+
Light
73+
</Button>
74+
<Button outline variant="dark">
75+
Dark
76+
</Button>
77+
<Button outline variant="#804FCE">
78+
Custom color
79+
</Button>
80+
<Button outline variant={null}>
81+
No variant
82+
</Button>
83+
</Boxer>
84+
)
85+
}
86+
87+
render(<Example />)
88+
```
89+
4190
## Scales
4291

4392
Set scales using `scale` prop like `"xs"`, `"sm"`, `"lg"` or `"xl"`. The default scale is `"base"`.

0 commit comments

Comments
 (0)