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

Commit 3ac41ec

Browse files
committed
feat: simplify API & fixes theme bugs
BREAKING CHANGE: remove uiAs prop & uiAs helper
1 parent a7e7458 commit 3ac41ec

28 files changed

+186
-204
lines changed

docs/advanced/CustomComponent.mdx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,35 @@ menu: Advanced
44
---
55

66
import { Playground } from 'docz'
7-
import { Button, Alert, uiAs } from '@smooth-ui/core-sc'
7+
import { Button, Alert } from '@smooth-ui/core-sc'
88

99
# Custom component
1010

1111
Sometimes you may want to use a component but the resulting HTML tag is not the good one. Or you want to use a `Button` with another component like [the `Link` from React Router](https://reacttraining.com/react-router/web/api/Link).
1212

1313
You can do it using two approaches.
1414

15-
## Use "uiAs" property
15+
## Use "as" property
1616

17-
Every components accepts a `uiAs` property, it defines the base component used in each component.
17+
Every components accepts a `as` property, it defines the base component used in each component.
1818

1919
An example of an `Alert` that uses `span` as a component.
2020

2121
<Playground>
22-
<Alert uiAs="span" variant="primary">
22+
<Alert as="span" variant="primary">
2323
A span alert
2424
</Alert>
2525
</Playground>
2626

27-
## Use "uiAs" helper
27+
## Use "withComponent" helper
2828

29-
`uiAs` creates a new component with a predefined base component.
29+
`withComponent` creates a new component with a predefined base component.
3030

3131
An example of `Button` that will use `a` instead of `button`.
3232

3333
<Playground>
3434
{() => {
35-
// import { uiAs } from '@smooth-ui/core-sc'
36-
const LinkButton = uiAs(Button, 'a')
35+
const LinkButton = Button.withComponent('a')
3736
return <LinkButton href="#">A button as a link</LinkButton>
3837
}}
3938
</Playground>

examples/basics/src/emotion/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const BlackButton = styled(Button)`
88
color: black;
99
`
1010

11-
const DivButton = uiAs(Button, 'div')
11+
const DivButton = Button.withComponent('div')
1212

1313
const App = () => (
1414
<>
@@ -17,10 +17,10 @@ const App = () => (
1717
<Button>Basic</Button>
1818
</div>
1919
<div>
20-
<DivButton>{`uiAs(Button, 'div')`}</DivButton>
20+
<DivButton>{`Button.withComponent('div')`}</DivButton>
2121
</div>
2222
<div>
23-
<Button uiAs="div">{`<Button uiAs="div">`}</Button>
23+
<Button as="div">{`<Button as="div">`}</Button>
2424
</div>
2525
<div>
2626
<BlackButton>{`styled(Button)\`color: black\``}</BlackButton>

examples/basics/src/styled-components/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const BlackButton = styled(Button)`
66
color: black;
77
`
88

9-
const DivButton = uiAs(Button, 'div')
9+
const DivButton = Button.withComponent('div')
1010

1111
const App = () => (
1212
<>
@@ -15,10 +15,10 @@ const App = () => (
1515
<Button>Basic</Button>
1616
</div>
1717
<div>
18-
<DivButton>{`uiAs(Button, 'div')`}</DivButton>
18+
<DivButton>{`Button.withComponent('div')`}</DivButton>
1919
</div>
2020
<div>
21-
<Button uiAs="div">{`<Button uiAs="div">`}</Button>
21+
<Button as="div">{`<Button as="div">`}</Button>
2222
</div>
2323
<div>
2424
<BlackButton>{`styled(Button)\`color: black\``}</BlackButton>

packages/shared/core/Alert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import createComponent from './utils/createComponent'
66
const Alert = createComponent(() => ({
77
name: 'alert',
88
omitProps: ['variant'],
9-
style: css`
9+
style: p => css`
1010
position: relative;
1111
padding: ${th('alertPaddingY')} ${th('alertPaddingX')};
1212
margin-bottom: ${th('alertMarginBottom')};
1313
border: 1px solid transparent;
1414
border-radius: ${th('borderRadius')};
15-
${p => p.variant && mixin('alertVariant', p.variant)(p)};
15+
${p.variant && mixin('alertVariant', p.variant)(p)};
1616
`,
1717
propTypes: {
1818
children: PropTypes.node,

packages/shared/core/Breakpoint.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import createComponent from './utils/createComponent'
66
const Breakpoint = createComponent(() => ({
77
name: 'breakpoint',
88
omitProps: ['up', 'down'],
9-
style: css`
9+
style: p => css`
1010
display: none;
11-
${p => p.up && up(p.up, 'display: block;')};
12-
${p => p.down && down(p.down, 'display: block;')};
11+
${p.up && up(p.up, 'display: block;')};
12+
${p.down && down(p.down, 'display: block;')};
1313
`,
1414
propTypes: {
1515
children: PropTypes.node,

packages/shared/core/Button.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Button = createComponent(() => ({
2828
name: 'button',
2929
defaultComponent: 'button',
3030
omitProps: ['size', 'variant'],
31-
style: css`
31+
style: p => css`
3232
display: inline-block;
3333
padding: ${th('btnPaddingY')} ${th('btnPaddingX')};
3434
z-index: ${th('zIndexControl')};
@@ -47,8 +47,8 @@ const Button = createComponent(() => ({
4747
opacity: ${th('btnDisabledOpacity')};
4848
}
4949
50-
${p => p.size && sizeStyle[p.size]};
51-
${p => p.variant && mixin('btnVariant', p.variant)(p)};
50+
${p.size && sizeStyle[p.size]};
51+
${p.variant && mixin('btnVariant', p.variant)(p)};
5252
`,
5353
propTypes: {
5454
children: PropTypes.node,

packages/shared/core/Checkbox.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,24 @@ const invalidStyle = css`
7878
}
7979
`
8080

81-
const controlStyle = css`
81+
const getValidStyle = valid => {
82+
switch (valid) {
83+
case true:
84+
return validStyle
85+
case false:
86+
return invalidStyle
87+
default:
88+
return null
89+
}
90+
}
91+
92+
const controlStyle = p => css`
8293
input:focus + .sui-checkbox-content {
8394
border-color: ${th('controlFocusBorderColor')};
8495
box-shadow: ${mixin('controlFocusBoxShadow', 'primary')};
8596
}
8697
87-
${p => {
88-
switch (p.valid) {
89-
case true:
90-
return validStyle
91-
case false:
92-
return invalidStyle
93-
default:
94-
return null
95-
}
96-
}};
98+
${getValidStyle(p)};
9799
`
98100

99101
const containerSystem = compose(
@@ -137,7 +139,7 @@ const Checkbox = createComponent(() => ({
137139
)}
138140
</SwitchState>
139141
),
140-
style: css`
142+
style: p => css`
141143
display: inline-flex;
142144
align-items: center;
143145
justify-content: center;
@@ -185,8 +187,8 @@ const Checkbox = createComponent(() => ({
185187
background-color: ${th('inputDisabledBgColor')};
186188
}
187189
188-
${p => sizeStyle[p.size]};
189-
${p => p.control && controlStyle};
190+
${sizeStyle[p.size]};
191+
${p.control && controlStyle(p)};
190192
191193
${containerSystem.props};
192194

packages/shared/core/ControlFeedback.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import createComponent from './utils/createComponent'
66
const ControlFeedback = createComponent(() => ({
77
name: 'control-feedback',
88
omitProps: ['valid'],
9-
style: css`
9+
style: p => css`
1010
width: 100%;
1111
margin-top: 0.25rem;
1212
font-size: 80%;
13-
color: ${p => (p.valid ? th('success')(p) : th('danger')(p))};
13+
color: ${p.valid ? th('success')(p) : th('danger')(p)};
1414
`,
1515
propTypes: {
1616
children: PropTypes.node,

packages/shared/core/FormCheck.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import createComponent from './utils/createComponent'
55
const FormCheck = createComponent(() => ({
66
name: 'form-check',
77
omitProps: ['inline'],
8-
style: css`
8+
style: p => css`
99
display: flex;
1010
align-items: center;
1111
12-
${p =>
13-
p.inline &&
12+
${p.inline &&
1413
css`
1514
display: inline-flex;
1615
margin-right: 0.75rem;

packages/shared/core/FormCheckLabel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import createComponent from './utils/createComponent'
66
const FormCheckLabel = createComponent(() => ({
77
name: 'form-check-label',
88
defaultComponent: 'label',
9-
style: css`
9+
style: () => css`
1010
padding-left: 0.25rem;
1111
1212
[class*='disabled'] ~ & {

0 commit comments

Comments
 (0)