Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit e62ce21

Browse files
notandrewcodepretty
authored andcommitted
fix(radio buttons): Update radio button styles (#830)
* updating radio button styles * radios * updating other themes * adding theme support for dark/high contrast * updating styles for dark/high contrast themes * updating colors * fixing border colors and high contrast issues * -addressed comments * added changelog entry & updated to use interface for variables per PR feedback * remove comments * updated focus state & colors for all themes * this will work once the pxToRem issues are fixed * cleaning up code that isn't needed anymore * updating look of input in radio button example * update changelog
1 parent 22f0841 commit e62ce21

File tree

9 files changed

+153
-30
lines changed

9 files changed

+153
-30
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1717

1818
## [Unreleased]
1919

20+
### Fixes
21+
- Fix `RadioButtonGroup` Teams theme styles to be correct @notandrew ([#830](https://github.com/stardust-ui/react/pull/830))
22+
2023
<!--------------------------------[ v0.24.0 ]------------------------------- -->
2124
## [v0.24.0](https://github.com/stardust-ui/react/tree/v0.24.0) (2019-03-25)
2225
[Compare changes](https://github.com/stardust-ui/react/compare/v0.23.1...v0.24.0)

docs/src/examples/components/RadioGroup/Types/RadioGroupVerticalExample.shorthand.tsx

+25-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ class RadioGroupVerticalExample extends React.Component {
77
render() {
88
const { selectedValue } = this.state
99
return (
10-
<div>
10+
<div style={{ maxWidth: '400px' }}>
1111
The selected value is: {selectedValue}
1212
<Divider />
1313
<RadioGroup
1414
vertical
15-
defaultCheckedValue="capricciosa"
15+
defaultCheckedValue="prosciutto"
1616
items={this.getItems()}
1717
checkedValueChanged={this.handleChange}
1818
/>
@@ -22,21 +22,42 @@ class RadioGroupVerticalExample extends React.Component {
2222

2323
getItems() {
2424
return [
25-
{ name: 'pizza', key: 'Capricciosa', label: 'Capricciosa', value: 'capricciosa' },
25+
{
26+
name: 'pizza',
27+
key: 'Capricciosa',
28+
label: 'Capricciosa',
29+
value: 'capricciosa',
30+
},
2631
{
2732
name: 'pizza',
2833
key: 'Prosciutto',
2934
label: 'Prosciutto',
3035
value: 'prosciutto',
3136
disabled: true,
3237
},
38+
{
39+
name: 'pizza',
40+
key: 'Pepperoni',
41+
label: 'Pepperoni',
42+
value: 'pepperoni',
43+
},
3344
{
3445
name: 'pizza',
3546
key: 'Custom',
3647
label: (
3748
<Text>
3849
Choose your own{' '}
39-
<Input input={{ tabIndex: this.state.inputTabIndex }} inline placeholder="flavour" />
50+
<Input
51+
input={{ tabIndex: this.state.inputTabIndex }}
52+
inline
53+
styles={{
54+
fontSize: '12px',
55+
'& .ui-input__input': {
56+
padding: '2px 8px',
57+
},
58+
}}
59+
placeholder="flavour"
60+
/>
4061
</Text>
4162
),
4263
value: 'custom',

packages/react/src/themes/teams-dark/componentVariables.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export { default as ChatMessage } from './components/Chat/chatMessageVariables'
44
export { default as Divider } from './components/Divider/dividerVariables'
55
export { default as Header } from './components/Header/headerVariables'
66
export { default as Input } from './components/Input/inputVariables'
7+
export { default as RadioGroupItem } from './components/RadioGroup/radioGroupItemVariables'
78
export { default as Text } from './components/Text/textVariables'
89
export { default as TreeTitle } from './components/Tree/treeTitleVariables'
910
export { default as Menu } from './components/Menu/menuVariables'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { RadioGroupItemVariables } from 'src/themes/teams/components/RadioGroup/radioGroupItemVariables'
2+
3+
export default (siteVars: any): Partial<RadioGroupItemVariables> => ({
4+
textColorDefault: siteVars.gray02,
5+
textColorDefaultHoverFocus: siteVars.colors.white,
6+
textColorChecked: siteVars.colors.white,
7+
8+
iconBorderColorDefaultHover: siteVars.colors.white,
9+
iconBorderColorChecked: siteVars.brand06,
10+
11+
iconBackgroundColorChecked: siteVars.brand06,
12+
})

packages/react/src/themes/teams-high-contrast/componentVariables.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export { default as Divider } from './components/Divider/dividerVariables'
66
export { default as Header } from './components/Header/headerVariables'
77
export { default as Input } from './components/Input/inputVariables'
88
export { default as Menu } from './components/Menu/menuVariables'
9+
export { default as RadioGroupItem } from './components/RadioGroup/radioGroupItemVariables'
910
export { default as Text } from './components/Text/textVariables'
1011
export { default as TreeTitle } from './components/Tree/treeTitleVariables'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { RadioGroupItemVariables } from 'src/themes/teams/components/RadioGroup/radioGroupItemVariables'
2+
3+
export default (siteVars: any): Partial<RadioGroupItemVariables> => ({
4+
colorDisabled: siteVars.accessibleGreen,
5+
6+
textColorDefault: siteVars.white,
7+
textColorDefaultHoverFocus: siteVars.white,
8+
textColorChecked: siteVars.white,
9+
10+
iconBorderColorDefaultHover: siteVars.accessibleCyan,
11+
iconBorderColorChecked: siteVars.accessibleCyan,
12+
13+
iconBackgroundColorChecked: siteVars.accessibleCyan,
14+
})

packages/react/src/themes/teams-high-contrast/siteVariables.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const black = '#000'
77
export const white = '#fff'
88

99
export const accessibleYellow = '#ffff01'
10-
export const accessibleGreen = '#3ff23f'
10+
export const accessibleGreen = '#3ff23f' // always disabled color in high contrast
1111
export const accessibleCyan = '#1aebff'
1212

1313
export const red = '#f00'

packages/react/src/themes/teams/components/RadioGroup/radioGroupItemStyles.ts

+72-13
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,95 @@ import {
44
RadioGroupItemState,
55
} from '../../../../components/RadioGroup/RadioGroupItem'
66
import { RadioGroupItemVariables } from './radioGroupItemVariables'
7+
import Icon from '../../../../components/Icon/Icon'
78
import { pxToRem } from '../../../../lib'
89

10+
const restHoverFocusTextColor = textColor => ({
11+
color: textColor,
12+
13+
':hover': {
14+
color: textColor,
15+
},
16+
17+
':focus': {
18+
color: textColor,
19+
},
20+
})
21+
922
const radioStyles: ComponentSlotStylesInput<
1023
RadioGroupItemProps & RadioGroupItemState,
1124
RadioGroupItemVariables
1225
> = {
1326
root: ({ props: p, variables: v }): ICSSInJSStyle => ({
14-
alignItems: 'baseline',
27+
// can remove this after global style for border-box goes in
28+
boxSizing: 'border-box',
29+
30+
alignItems: 'center',
31+
borderStyle: 'solid',
32+
borderWidth: `${pxToRem(1)}`,
33+
borderColor: 'transparent',
34+
borderRadius: `${pxToRem(2)}`,
35+
color: v.textColorDefault,
1536
cursor: 'pointer',
1637
display: p.vertical ? 'flex' : 'inline-flex',
17-
fontWeight: 400,
18-
minHeight: '2.5rem',
19-
outline: 0,
38+
fontSize: v.textFontSize,
2039
padding: v.padding,
40+
outline: 0,
41+
42+
':hover': {
43+
color: v.textColorDefaultHoverFocus,
44+
45+
[`& .${Icon.className}`]: {
46+
color: v.iconBorderColorDefaultHover,
47+
},
48+
},
49+
50+
':focus': {
51+
color: v.textColorDefaultHoverFocus,
52+
},
53+
54+
...(p.checked && {
55+
...restHoverFocusTextColor(v.textColorChecked),
56+
}),
57+
2158
...(p.disabled && {
22-
color: v.colorDisabled,
59+
...restHoverFocusTextColor(v.colorDisabled),
60+
}),
61+
62+
...(p.isFromKeyboard && {
63+
borderColor: v.focusInnerBorderColor,
64+
boxShadow: `0 0 0 ${pxToRem(1)} ${v.focusOuterBorderColor}`,
2365
}),
2466
}),
2567

2668
icon: ({ props: p, variables: v }): ICSSInJSStyle => ({
27-
margin: `0 ${pxToRem(10)} 0 0`,
28-
color: p.checked ? v.colorChecked : v.color,
29-
backgroundColor: p.checked ? v.colorBackgroundChecked : v.colorBackground,
30-
borderColor: p.checked ? v.colorBorderChecked : v.colorBorder,
31-
outlineColor: v.color,
69+
// overrides from icon styles
70+
backgroundColor: 'transparent',
71+
boxShadow: 'none',
3272

33-
...(p.isFromKeyboard && {
34-
// this creates both inset and outset box shadow that some readers (NVDA) show when radio is not checked but it is focused
35-
boxShadow: `0 0 0 ${pxToRem(1)} ${v.color},` + `0 0 0 ${pxToRem(2)} ${v.color} inset`,
73+
// can remove this after global style for border-box goes in
74+
boxSizing: 'border-box',
75+
76+
borderStyle: 'solid',
77+
borderWidth: `${pxToRem(1)}`,
78+
borderColor: 'currentColor',
79+
margin: `0 ${pxToRem(12)} 0 0`,
80+
height: `${pxToRem(12)}`,
81+
width: `${pxToRem(12)}`,
82+
83+
...(p.checked && {
84+
backgroundColor: v.iconBackgroundColorChecked,
85+
borderColor: v.iconBorderColorChecked,
3686
}),
87+
88+
...(p.disabled && {
89+
borderColor: v.colorDisabled,
90+
}),
91+
92+
...(p.checked &&
93+
p.disabled && {
94+
backgroundColor: v.colorDisabled,
95+
}),
3796
}),
3897
}
3998

Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
import { pxToRem } from '../../../../lib'
22

33
export type RadioGroupItemVariables = {
4-
color: string
5-
colorChecked: string
64
colorDisabled: string
75

8-
colorBorder: string
9-
colorBorderChecked: string
6+
// can these be global colors so we don't have to define for every component?
7+
focusInnerBorderColor: string
8+
focusOuterBorderColor: string
109

11-
colorBackground: string
12-
colorBackgroundChecked: string
10+
textFontSize: string
11+
12+
textColorDefault: string
13+
textColorDefaultHoverFocus: string
14+
textColorChecked: string
15+
16+
iconBorderColorDefaultHover: string
17+
iconBorderColorChecked: string
18+
19+
iconBackgroundColorChecked: string
1320

1421
padding: string
1522
}
1623

1724
export default (siteVars: any): RadioGroupItemVariables => ({
18-
color: siteVars.colors.primary[500],
19-
colorChecked: siteVars.colors.white,
2025
colorDisabled: siteVars.gray06,
26+
focusInnerBorderColor: siteVars.colors.white,
27+
focusOuterBorderColor: siteVars.colors.black,
28+
29+
textFontSize: siteVars.fontSizes.medium,
30+
31+
textColorDefault: siteVars.gray02,
32+
textColorDefaultHoverFocus: siteVars.colors.grey[900],
33+
textColorChecked: siteVars.colors.grey[900],
2134

22-
colorBorder: siteVars.colors.primary[500],
23-
colorBorderChecked: siteVars.colors.white,
35+
iconBorderColorDefaultHover: siteVars.colors.grey[900],
36+
iconBorderColorChecked: siteVars.colors.primary[500],
2437

25-
colorBackground: siteVars.colors.white,
26-
colorBackgroundChecked: siteVars.colors.primary[500],
38+
iconBackgroundColorChecked: siteVars.colors.primary[500],
2739

2840
padding: `0 ${pxToRem(4)}`,
2941
})

0 commit comments

Comments
 (0)