Skip to content

Commit de126e9

Browse files
committed
feat(ui-themes,ui-range-input): rework RangeInput
INSTUI-4805
1 parent a7ebb30 commit de126e9

File tree

5 files changed

+53
-113
lines changed

5 files changed

+53
-113
lines changed

docs/guides/upgrade-guide.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ type: example
135135
<TextInput renderLabel="Name" placeholder="Doe, John Doe"/>
136136
</InstUISettingsProvider>
137137
```
138+
138139
### Breadcrumb
139140

140-
#### New tokens
141+
#### New tokens
141142

142143
- gapSm - Gap spacing for small size breadcrumbs
143144
- gapMd - Gap spacing for medium size breadcrumbs
@@ -255,6 +256,12 @@ type: example
255256
- theme variable `invalidAsteriskColor` is now removed
256257
- `error` or `success` messages are no longer displayed when the component is '`readOnly` or `disabled`
257258

259+
### RangeInput
260+
261+
- theme variable `handleShadow` is now renamed to `boxShadow`
262+
- theme variable `handleFocusRingSize` is now removed style uses the `focusOutline.width` token
263+
- theme variable `handleFocusRingColor` is now removed style uses the `sharedTokens.focusOutline.onColor` token
264+
258265
### TextInput
259266

260267
- theme variable `requiredInvalidColor` is now removed

packages/ui-range-input/src/RangeInput/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ import { warn } from '@instructure/console'
2828
import { ContextView } from '@instructure/ui-view'
2929
import { FormField } from '@instructure/ui-form-field'
3030
import { addEventListener } from '@instructure/ui-dom-utils'
31-
import { withStyleRework as withStyle } from '@instructure/emotion'
31+
import { withStyle } from '@instructure/emotion'
3232
import {
3333
omitProps,
3434
pickProps,
3535
withDeterministicId
3636
} from '@instructure/ui-react-utils'
3737

3838
import generateStyle from './styles'
39-
import generateComponentTheme from './theme'
4039

4140
import type { RangeInputProps, RangeInputState } from './props'
4241
import { allowedProps } from './props'
@@ -47,7 +46,7 @@ category: components
4746
---
4847
**/
4948
@withDeterministicId()
50-
@withStyle(generateStyle, generateComponentTheme)
49+
@withStyle(generateStyle)
5150
class RangeInput extends Component<RangeInputProps, RangeInputState> {
5251
static readonly componentId = 'RangeInput'
5352
static outputLocatorAttribute = 'data-range-output'

packages/ui-range-input/src/RangeInput/styles.ts

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,29 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import type { RangeInputTheme } from '@instructure/shared-types'
25+
import type {
26+
NewComponentTypes,
27+
SharedTokens,
28+
TokenBoxshadowValueInst
29+
} from '@instructure/ui-themes'
2630
import type { RangeInputProps, RangeInputStyle } from './props'
31+
import { darken, alpha } from '@instructure/ui-color-utils'
32+
import { boxShadowObjectToString } from '@instructure/ui-themes'
33+
34+
/**
35+
* Converts a boxShadow object with multiple shadows to CSS string
36+
*/
37+
const convertBoxShadow = (boxShadowObj: any): string => {
38+
if (
39+
boxShadowObj.type &&
40+
(boxShadowObj.type === 'dropShadow' || boxShadowObj.type === 'innerShadow')
41+
) {
42+
return boxShadowObjectToString(boxShadowObj)
43+
}
44+
return Object.values(boxShadowObj)
45+
.map((shadow) => boxShadowObjectToString(shadow as TokenBoxshadowValueInst))
46+
.join(', ')
47+
}
2748

2849
/**
2950
* ---
@@ -36,8 +57,9 @@ import type { RangeInputProps, RangeInputStyle } from './props'
3657
* @return {Object} The final style object, which will be used in the component
3758
*/
3859
const generateStyle = (
39-
componentTheme: RangeInputTheme,
40-
props: RangeInputProps
60+
componentTheme: NewComponentTypes['RangeInput'],
61+
props: RangeInputProps,
62+
sharedTokens: SharedTokens
4163
): RangeInputStyle => {
4264
const { size, thumbVariant } = props
4365
const valueSizeVariants = {
@@ -60,7 +82,9 @@ const generateStyle = (
6082

6183
const trackStyle = {
6284
borderRadius: '0.312em',
63-
borderColor: 'transparent',
85+
borderWidth: '1px',
86+
borderStyle: 'solid',
87+
borderColor: componentTheme.trackBorderColor,
6488
color: 'transparent',
6589
cursor: 'pointer',
6690
background: componentTheme.trackBackground,
@@ -73,7 +97,7 @@ const generateStyle = (
7397
deprecated: {
7498
width: componentTheme.handleSize,
7599
height: componentTheme.handleSize,
76-
boxShadow: `0 0.0625rem 0 ${componentTheme.handleShadowColor}`
100+
boxShadow: `0 0.0625rem 0 ${darken(componentTheme.handleShadowColor)}`
77101
},
78102
accessible: {
79103
width: borderedHandleSize,
@@ -82,7 +106,7 @@ const generateStyle = (
82106
borderColor: componentTheme.handleBorderColor,
83107
borderStyle: 'solid',
84108
boxSizing: 'border-box',
85-
boxShadow: componentTheme.handleShadow
109+
boxShadow: convertBoxShadow(componentTheme.boxShadow)
86110
}
87111
}
88112

@@ -101,25 +125,29 @@ const generateStyle = (
101125

102126
const thumbPosition = {
103127
deprecated: {
104-
marginTop: `calc(-1 * ${componentTheme.handleSize} / 4)`
128+
marginTop: `calc(-1 * ${componentTheme.handleSize} / 4 - 1px)`
105129
},
106130
accessible: {
107-
marginTop: `calc(-1 * ${borderedHandleSize} / 4)`
131+
marginTop: `calc(-1 * ${borderedHandleSize} / 4 - 1px)`
108132
}
109133
}
110134

111135
const thumbFocusActiveStyle = {
112136
deprecated: {
113137
background: componentTheme.handleFocusBackground,
114-
boxShadow: `0 0.0625rem 0 ${componentTheme.handleShadowColor}, 0 0 0 ${componentTheme.handleFocusOutlineWidth} ${componentTheme.handleFocusOutlineColor}`
138+
boxShadow: `0 0.0625rem 0 ${darken(
139+
componentTheme.handleShadowColor
140+
)}, 0 0 0 ${componentTheme.handleFocusOutlineWidth} ${alpha(
141+
componentTheme.handleFocusOutlineColor,
142+
40
143+
)}`
115144
},
116145
accessible: {
117146
background: componentTheme.handleFocusBackground,
118147
boxShadow:
119-
componentTheme.handleShadow +
120-
', ' +
148+
`${convertBoxShadow(componentTheme.boxShadow)}, ` +
121149
`inset 0 0 0 ${componentTheme.handleFocusInset} ${componentTheme.handleFocusBackground}, ` +
122-
`inset 0 0 0 calc(${componentTheme.handleFocusInset} + ${componentTheme.handleFocusRingSize}) ${componentTheme.handleFocusRingColor}`
150+
`inset 0 0 0 calc(${componentTheme.handleFocusInset} + ${sharedTokens.focusOutline.width}) ${sharedTokens.focusOutline.onColor}`
123151
}
124152
}
125153

packages/ui-range-input/src/RangeInput/theme.ts

Lines changed: 0 additions & 96 deletions
This file was deleted.

packages/ui-themes/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
additionalPrimitives
5151
} from './sharedThemeTokens/colors/primitives'
5252
import dataVisualization from './sharedThemeTokens/colors/dataVisualization'
53+
import { boxShadowObjectToString } from './utils/boxShadowObjectToString'
5354

5455
import type {
5556
Canvas as NewCanvas,
@@ -85,7 +86,8 @@ export {
8586
canvasHighContrast,
8687
primitives,
8788
additionalPrimitives,
88-
dataVisualization
89+
dataVisualization,
90+
boxShadowObjectToString
8991
}
9092
export default canvas
9193
export type {

0 commit comments

Comments
 (0)