Skip to content

Commit 1505fba

Browse files
authored
feat(localized-text-input): support custom theming, use design tokens (#630)
* feat: support custom themes for localized-text-input * chore: omit props list for spec
1 parent 3373db0 commit 1505fba

File tree

3 files changed

+58
-21
lines changed

3 files changed

+58
-21
lines changed

src/components/inputs/localized-text-input/localized-text-input.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ class LocalizedInput extends React.Component {
7373
display: flex;
7474
`}
7575
>
76-
<label htmlFor={this.props.id} css={getLanguageLabelStyles()}>
76+
<label
77+
htmlFor={this.props.id}
78+
css={theme => getLanguageLabelStyles(this.props, theme)}
79+
>
7780
{/* FIXME: add proper tone for disabled when tones are refactored */}
7881
<Text.Detail tone="secondary">
7982
{this.props.language.toUpperCase()}
@@ -89,7 +92,7 @@ class LocalizedInput extends React.Component {
8992
onFocus={this.props.onFocus}
9093
disabled={this.props.isDisabled}
9194
placeholder={this.props.placeholder}
92-
css={getLocalizedInputStyles(this.props)}
95+
css={theme => getLocalizedInputStyles(this.props, theme)}
9396
readOnly={this.props.isReadOnly}
9497
autoFocus={this.props.isAutofocussed}
9598
/* ARIA */
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { css } from '@emotion/core';
22
import vars from '../../../../materials/custom-properties';
3+
import designTokens from '../../../../materials/design-tokens';
34
import { getInputStyles } from '../styles';
45

56
// NOTE: order is important here
67
// * a disabled-field currently does not display warning/error-states so it takes precedence
78
// * a readonly-field cannot be changed, but it might be relevant for validation, so error and warning are checked first
89
// how you can interact with the field is controlled separately by the props, this only influences visuals
9-
const getLocalizedInputStyles = props => [
10-
getInputStyles(props),
10+
const getLocalizedInputStyles = (props, theme) => [
11+
getInputStyles(props, theme),
1112
css`
1213
border-top-left-radius: 0;
1314
border-bottom-left-radius: 0;
@@ -16,22 +17,36 @@ const getLocalizedInputStyles = props => [
1617
`,
1718
];
1819

19-
const getLanguageLabelStyles = () => css`
20-
/* avoid wrapping label onto new lines */
21-
flex: 1 0 auto;
22-
box-sizing: border-box;
23-
color: ${vars.fontColorDisabled};
24-
height: ${vars.sizeHeightInput};
25-
line-height: ${vars.sizeHeightInput};
26-
background-color: ${vars.backgroundColorInputDisabled};
27-
border-top-left-radius: ${vars.borderRadiusInput};
28-
border-bottom-left-radius: ${vars.borderRadiusInput};
29-
border: 1px ${vars.borderColorInputDisabled} solid;
30-
padding: 0 ${vars.spacing8};
31-
transition: ${vars.transitionStandard};
32-
border-right: 0;
33-
box-shadow: none;
34-
appearance: none;
35-
`;
20+
const getLanguageLabelStyles = (props, theme) => {
21+
const overwrittenVars = {
22+
...vars,
23+
...theme,
24+
};
25+
26+
return css`
27+
/* avoid wrapping label onto new lines */
28+
flex: 1 0 auto;
29+
box-sizing: border-box;
30+
color: ${overwrittenVars[designTokens.fontColorForInputWhenDisabled]};
31+
height: ${vars.sizeHeightInput};
32+
line-height: ${vars.sizeHeightInput};
33+
background-color: ${overwrittenVars[
34+
designTokens.backgroundColorForInputWhenDisabled
35+
]};
36+
border-top-left-radius: ${overwrittenVars[
37+
designTokens.borderRadiusForInput
38+
]};
39+
border-bottom-left-radius: ${overwrittenVars[
40+
designTokens.borderRadiusForInput
41+
]};
42+
border: 1px ${overwrittenVars[designTokens.borderColorForInputWhenDisabled]}
43+
solid;
44+
padding: 0 ${vars.spacing8};
45+
transition: ${vars.transitionStandard};
46+
border-right: 0;
47+
box-shadow: none;
48+
appearance: none;
49+
`;
50+
};
3651

3752
export { getLocalizedInputStyles, getLanguageLabelStyles };

src/components/inputs/localized-text-input/localized-text-input.visualroute.js

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { LocalizedTextInput, ErrorMessage } from 'ui-kit';
3+
import { ThemeProvider } from 'emotion-theming';
34
import { Suite, Spec } from '../../../../test/percy';
45

56
const value = {
@@ -8,6 +9,14 @@ const value = {
89
es: 'hola mundo',
910
};
1011

12+
const theme = {
13+
colorSurface: 'black',
14+
colorSolid: 'white',
15+
colorNeutral60: 'rgba(0,0,0,0.60)',
16+
colorNeutral: 'rgba(0,0,0,0.60)',
17+
colorAccent98: 'rgba(0,0,0,0.98)',
18+
};
19+
1120
export const routePath = '/localized-text-input';
1221

1322
export const component = () => (
@@ -102,5 +111,15 @@ export const component = () => (
102111
hasError={true}
103112
/>
104113
</Spec>
114+
<Spec label="with a custom (dark) theme" omitPropsList={true}>
115+
<ThemeProvider theme={theme}>
116+
<LocalizedTextInput
117+
value={value}
118+
onChange={() => {}}
119+
selectedLanguage="en"
120+
horizontalConstraint="m"
121+
/>
122+
</ThemeProvider>
123+
</Spec>
105124
</Suite>
106125
);

0 commit comments

Comments
 (0)