Skip to content

Commit a763a0b

Browse files
Fedor Kulikovkodiakhq[bot]
Fedor Kulikov
authored andcommitted
feat(flat-button): add inverted tone (#1175)
* feat(flat-button): add `inverted` tone * fix(flat-button): use dark theme for inverted color VRT scenario * chore: fix visual spec
1 parent 71fc660 commit a763a0b

File tree

15 files changed

+61
-22
lines changed

15 files changed

+61
-22
lines changed

materials/custom-properties.css

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
--font-color-for-input-when-warning: #f16d0e;
105105
--font-color-for-tag: #1a1a1a;
106106
--font-color-for-tag-when-disabled: hsl(0, 0%, 60%);
107+
--font-color-for-text-when-inverted: #fff;
107108
--font-family: 'Open Sans', sans-serif;
108109
--placeholder-font-color-for-input: hsl(0, 0%, 60%);
109110
--font-size-for-input: 1rem;

materials/custom-properties.js

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export default {
9999
fontColorForInputWhenWarning: '#f16d0e',
100100
fontColorForTag: '#1a1a1a',
101101
fontColorForTagWhenDisabled: 'hsl(0, 0%, 60%)',
102+
fontColorForTextWhenInverted: '#fff',
102103
fontFamily: "'Open Sans', sans-serif",
103104
placeholderFontColorForInput: 'hsl(0, 0%, 60%)',
104105
fontSizeForInput: '1rem',

materials/custom-properties.json

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"--font-color-for-input-when-warning": "#f16d0e",
8989
"--font-color-for-tag": "#1a1a1a",
9090
"--font-color-for-tag-when-disabled": "hsl(0, 0%, 60%)",
91+
"--font-color-for-text-when-inverted": "#fff",
9192
"--font-family": "'Open Sans', sans-serif",
9293
"--placeholder-font-color-for-input": "hsl(0, 0%, 60%)",
9394
"--font-size-for-input": "1rem",

materials/custom-properties.ts

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ type CustomProperties = {
9595
fontColorForInputWhenWarning: '#f16d0e',
9696
fontColorForTag: '#1a1a1a',
9797
fontColorForTagWhenDisabled: 'hsl(0, 0%, 60%)',
98+
fontColorForTextWhenInverted: '#fff',
9899
fontFamily: "'Open Sans', sans-serif",
99100
placeholderFontColorForInput: 'hsl(0, 0%, 60%)',
100101
fontSizeForInput: '1rem',
@@ -203,6 +204,7 @@ const customProperties: CustomProperties = {
203204
fontColorForInputWhenWarning: '#f16d0e',
204205
fontColorForTag: '#1a1a1a',
205206
fontColorForTagWhenDisabled: 'hsl(0, 0%, 60%)',
207+
fontColorForTextWhenInverted: '#fff',
206208
fontFamily: "'Open Sans', sans-serif",
207209
placeholderFontColorForInput: 'hsl(0, 0%, 60%)',
208210
fontSizeForInput: '1rem',

materials/design-tokens.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default {
3030
fontColorForInputWhenWarning: 'colorWarning',
3131
fontColorForTag: 'colorSolid',
3232
fontColorForTagWhenDisabled: 'colorNeutral60',
33+
fontColorForTextWhenInverted: 'colorSurface',
3334
fontFamily: 'fontFamilyBody',
3435
placeholderFontColorForInput: 'colorNeutral60',
3536
fontSizeForInput: 'fontSizeM',

materials/internals/definition.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,17 @@ states:
145145
description: 'When the element has invalid input'
146146
selected:
147147
description: 'When the element is selected'
148+
inverted:
149+
description: 'When the element has inverted colors'
148150
componentGroups:
149151
input:
150152
description: 'Input elements'
151153
tag:
152154
description: 'Tag elements'
153155
tag-warning:
154156
description: 'Tag elements with type warning'
157+
text:
158+
description: 'Text elements'
155159

156160
decisionGroups:
157161
backgroundColors:
@@ -247,6 +251,9 @@ decisionGroups:
247251
font-color-for-tag-when-disabled:
248252
description: ''
249253
choice: color-neutral-60
254+
font-color-for-text-when-inverted:
255+
description: ''
256+
choice: color-surface
250257

251258
fontFamily:
252259
label: Font family

philosophy/FORMS.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,21 @@ In this case, there is another thing we need to be aware of: When a form is subm
323323
We can pass an `onSubmit` property to Formik. That function will be called with `values` and `formik`.
324324

325325
```js
326-
import omitEmpty from 'omit-empty'
327-
import validate from './validate'
326+
import omitEmpty from 'omit-empty';
327+
import validate from './validate';
328328

329329
<GetProduct id="party-parrot">
330330
{product => (
331331
<Formik
332332
initialValues={docToFormValues(product)}
333333
validate={validate}
334334
onSubmit={(values, formik) => {
335-
console.log(values)
335+
console.log(values);
336336
}}
337337
render={/* same as before */}
338338
/>
339339
)}
340-
</GetProduct>
340+
</GetProduct>;
341341
```
342342

343343
We can then do anything from `onSubmit`. Most likely we'll want to make an async call and then reset the form state. We can do that like this:

src/components/buttons/flat-button/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ iconClass label url onClick
2626

2727
#### Properties
2828

29-
| Props | Type | Required | Values | Default | Description |
30-
| -------------- | --------------------- | :------: | --------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
31-
| `tone` | `oneOf` | - | `primary`, `secondary` | `primary` | - |
32-
| `type` | `string` | - | `submit`, `reset`, `button` | `button` | Used as the HTML `type` attribute. |
33-
| `label` | `string` || - | - | Should describe what the button is for |
34-
| `onClick` | `func` || - | - | What the button will trigger when clicked |
35-
| `icon` | `element` | - | - | - | The icon of the button |
36-
| `iconPosition` | `oneOf` | - | `left`, `right` | `left` | The position of the icon |
37-
| `isDisabled` | `boolean` | - | - | - | Tells when the button should present a disabled state |
38-
| `as` | `string` or `element` | - | - | - | You may pass in a string like "a" to have the button render as an anchor tag instead. Or you could pass in a React Component, like a `Link`. |
29+
| Props | Type | Required | Values | Default | Description |
30+
| -------------- | --------------------- | :------: | --------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
31+
| `tone` | `oneOf` | - | `primary`, `secondary`, `iverted` | `primary` | - |
32+
| `type` | `string` | - | `submit`, `reset`, `button` | `button` | Used as the HTML `type` attribute. |
33+
| `label` | `string` || - | - | Should describe what the button is for |
34+
| `onClick` | `func` || - | - | What the button will trigger when clicked |
35+
| `icon` | `element` | - | - | - | The icon of the button |
36+
| `iconPosition` | `oneOf` | - | `left`, `right` | `left` | The position of the icon |
37+
| `isDisabled` | `boolean` | - | - | - | Tells when the button should present a disabled state |
38+
| `as` | `string` or `element` | - | - | - | You may pass in a string like "a" to have the button render as an anchor tag instead. Or you could pass in a React Component, like a `Link`. |
3939

4040
The component further forwards all valid HTML attributes to the underlying `button` component.
4141

src/components/buttons/flat-button/flat-button.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const getIconElement = props => {
1818
else if (props.tone === 'primary') iconColor = 'primary';
1919
else if (props.tone === 'secondary' && props.isMouseOver)
2020
iconColor = 'warning';
21+
else if (props.tone === 'inverted') iconColor = 'surface';
2122

2223
return React.cloneElement(props.icon, {
2324
size: 'medium',
@@ -33,6 +34,8 @@ const getTextColor = (tone, isHover = false, overwrittenVars) => {
3334
: overwrittenVars.colorPrimary;
3435
case 'secondary':
3536
return overwrittenVars.colorSolid;
37+
case 'inverted':
38+
return overwrittenVars.fontColorForTextWhenInverted;
3639
default:
3740
return 'inherit';
3841
}
@@ -110,7 +113,7 @@ export const FlatButton = props => {
110113
FlatButton.displayName = 'FlatButton';
111114
FlatButton.propTypes = {
112115
as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
113-
tone: PropTypes.oneOf(['primary', 'secondary']),
116+
tone: PropTypes.oneOf(['primary', 'secondary', 'inverted']),
114117
type: PropTypes.oneOf(['submit', 'reset', 'button']),
115118
label: PropTypes.string.isRequired,
116119
onClick: PropTypes.func.isRequired,

src/components/buttons/flat-button/flat-button.story.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ storiesOf('Components|Buttons', module)
2020
<Section>
2121
<FlatButton
2222
type={select('type', ['submit', 'reset', 'button'], 'button')}
23-
tone={select('tone', ['primary', 'secondary'], 'primary')}
23+
tone={select('tone', ['primary', 'secondary', 'inverted'], 'primary')}
2424
label={text('label', 'Accessibility text')}
2525
icon={React.createElement(
2626
icons[select('icon', iconNames, iconNames[0])]

src/components/buttons/flat-button/flat-button.visualroute.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { ThemeProvider } from 'emotion-theming';
33
import { FlatButton, InformationIcon } from 'ui-kit';
44
import { Suite, Spec } from '../../../../test/percy';
5+
import vars from '../../../../materials/custom-properties';
56

67
export const routePath = '/flat-button';
78

@@ -44,10 +45,20 @@ export const component = ({ themes }) => (
4445
/>
4546
</Spec>
4647
<ThemeProvider theme={themes.darkTheme}>
47-
<Spec label="secondary">
48+
<Spec label="inverted" listPropsOfNestedChild>
49+
<ThemeProvider theme={vars}>
50+
<FlatButton
51+
tone="inverted"
52+
label="A label text"
53+
onClick={() => {}}
54+
icon={<InformationIcon />}
55+
/>
56+
</ThemeProvider>
57+
</Spec>
58+
<Spec label="secondary in dark theme">
4859
<FlatButton
4960
tone="secondary"
50-
label="Inverted"
61+
label="A label text"
5162
onClick={() => {}}
5263
icon={<InformationIcon />}
5364
/>

src/components/inputs/async-creatable-select-input/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { AsyncCreatableSelectInput } from '@commercetools-frontend/ui-kit';
1313
name="form-field-name"
1414
value={value}
1515
onChange={handleChange}
16-
options={[{ value: 'one', label: 'One' }, { value: 'two', label: 'Two' }]}
16+
options={[
17+
{ value: 'one', label: 'One' },
18+
{ value: 'two', label: 'Two' },
19+
]}
1720
/>;
1821
```
1922

src/components/inputs/async-select-input/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { AsyncSelectInput } from '@commercetools-frontend/ui-kit';
1313
name="form-field-name"
1414
value={value}
1515
onChange={handleChange}
16-
options={[{ value: 'one', label: 'One' }, { value: 'two', label: 'Two' }]}
16+
options={[
17+
{ value: 'one', label: 'One' },
18+
{ value: 'two', label: 'Two' },
19+
]}
1720
/>;
1821
```
1922

src/components/inputs/creatable-select-input/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { CreatableSelectInput } from '@commercetools-frontend/ui-kit';
1313
name="form-field-name"
1414
value={value}
1515
onChange={handleChange}
16-
options={[{ value: 'one', label: 'One' }, { value: 'two', label: 'Two' }]}
16+
options={[
17+
{ value: 'one', label: 'One' },
18+
{ value: 'two', label: 'Two' },
19+
]}
1720
/>;
1821
```
1922

src/components/inputs/select-input/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { SelectInput } from '@commercetools-frontend/ui-kit';
1313
name="form-field-name"
1414
value={value}
1515
onChange={event => alert(event.target.value)}
16-
options={[{ value: 'one', label: 'One' }, { value: 'two', label: 'Two' }]}
16+
options={[
17+
{ value: 'one', label: 'One' },
18+
{ value: 'two', label: 'Two' },
19+
]}
1720
/>;
1821
```
1922

0 commit comments

Comments
 (0)