Skip to content

Commit 257139f

Browse files
authored
feat(localized-multiline-text-input): support theming
1 parent 1505fba commit 257139f

File tree

3 files changed

+55
-19
lines changed

3 files changed

+55
-19
lines changed

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

+18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import React from 'react';
2+
import { ThemeProvider } from 'emotion-theming';
23
import {
34
LocalizedMultilineTextInput,
45
ErrorMessage,
56
WarningMessage,
67
} from 'ui-kit';
78
import { Suite, Spec } from '../../../../test/percy';
89

10+
const darkTheme = {
11+
colorSurface: 'black',
12+
colorSolid: 'white',
13+
colorNeutral60: 'rgba(255,255,255,0.60)',
14+
colorNeutral: 'rgba(255,255,255,0.60)',
15+
colorAccent98: 'rgba(0,0,0,0.98)',
16+
};
17+
918
const lorem =
1019
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.';
1120

@@ -155,5 +164,14 @@ export const component = () => (
155164
hasWarning={true}
156165
/>
157166
</Spec>
167+
<ThemeProvider theme={darkTheme}>
168+
<Spec label="with custom theme" inverted>
169+
<LocalizedMultilineTextInput
170+
value={value}
171+
onChange={() => {}}
172+
selectedLanguage="en"
173+
/>
174+
</Spec>
175+
</ThemeProvider>
158176
</Suite>
159177
);

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export default class TranslationInput extends React.Component {
9090
display: flex;
9191
`}
9292
>
93-
<label htmlFor={this.props.id} css={getLanguageLabelStyles}>
93+
<label
94+
htmlFor={this.props.id}
95+
css={theme => getLanguageLabelStyles(this.props, theme)}
96+
>
9497
{/* FIXME: add proper tone for disabled when tones are refactored */}
9598
<Text.Detail tone="secondary">
9699
{this.props.language.toUpperCase()}
@@ -111,7 +114,7 @@ export default class TranslationInput extends React.Component {
111114
}}
112115
disabled={this.props.isDisabled}
113116
placeholder={this.props.placeholder}
114-
css={getTextareaStyles(this.props)}
117+
css={theme => getTextareaStyles(this.props, theme)}
115118
readOnly={this.props.isReadOnly}
116119
autoFocus={this.props.isAutofocussed}
117120
/* ARIA */
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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
/* we need this line-height to achieve 32px height when the component has only one row */
@@ -9,9 +10,9 @@ const sizeInputLineHeight = '22px';
910
// * a disabled-field currently does not display warning/error-states so it takes precedence
1011
// * a readonly-field cannot be changed, but it might be relevant for validation, so error and warning are checked first
1112
// how you can interact with the field is controlled separately by the props, this only influences visuals
12-
const getTextareaStyles = props => {
13+
const getTextareaStyles = (props, theme) => {
1314
const baseStyles = [
14-
getInputStyles(props),
15+
getInputStyles(props, theme),
1516
css`
1617
border-top-left-radius: 0;
1718
border-bottom-left-radius: 0;
@@ -31,20 +32,34 @@ const getTextareaStyles = props => {
3132
return baseStyles;
3233
};
3334

34-
const getLanguageLabelStyles = () => css`
35-
/* avoid wrapping label onto new lines */
36-
flex: 1 0 auto;
37-
color: ${vars.fontColorDisabled};
38-
line-height: calc(${vars.sizeHeightInput} - 2 * ${vars.borderRadius1});
39-
background-color: ${vars.backgroundColorInputDisabled};
40-
border-top-left-radius: ${vars.borderRadiusInput};
41-
border-bottom-left-radius: ${vars.borderRadiusInput};
42-
border: 1px ${vars.borderColorInputDisabled} solid;
43-
padding: 0 ${vars.spacing8};
44-
transition: ${vars.transitionStandard};
45-
border-right: 0;
46-
box-shadow: none;
47-
appearance: none;
48-
`;
35+
const getLanguageLabelStyles = (props, theme) => {
36+
const overwrittenVars = {
37+
...vars,
38+
...theme,
39+
};
40+
41+
return css`
42+
/* avoid wrapping label onto new lines */
43+
flex: 1 0 auto;
44+
color: ${overwrittenVars[designTokens.fontColorForInputWhenDisabled]};
45+
line-height: calc(${vars.sizeHeightInput} - 2 * ${vars.borderRadius1});
46+
background-color: ${overwrittenVars[
47+
designTokens.backgroundColorForInputWhenDisabled
48+
]};
49+
border-top-left-radius: ${overwrittenVars[
50+
designTokens.borderRadiusForInput
51+
]};
52+
border-bottom-left-radius: ${overwrittenVars[
53+
designTokens.borderRadiusForInput
54+
]};
55+
border: 1px ${overwrittenVars[designTokens.borderColorForInputWhenDisabled]}
56+
solid;
57+
padding: 0 ${vars.spacing8};
58+
transition: ${vars.transitionStandard};
59+
border-right: 0;
60+
box-shadow: none;
61+
appearance: none;
62+
`;
63+
};
4964

5065
export { getTextareaStyles, getLanguageLabelStyles };

0 commit comments

Comments
 (0)