-
Notifications
You must be signed in to change notification settings - Fork 106
[v12] feat(ui-range-input): rework RangeInput #2318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v12
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,10 @@ | |
| * SOFTWARE. | ||
| */ | ||
|
|
||
| import type { RangeInputTheme } from '@instructure/shared-types' | ||
| import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes' | ||
| import type { RangeInputProps, RangeInputStyle } from './props' | ||
| import { darken, alpha } from '@instructure/ui-color-utils' | ||
| import { boxShadowObjectsToCSSString } from '@instructure/ui-themes' | ||
|
|
||
| /** | ||
| * --- | ||
|
|
@@ -36,31 +38,34 @@ import type { RangeInputProps, RangeInputStyle } from './props' | |
| * @return {Object} The final style object, which will be used in the component | ||
| */ | ||
| const generateStyle = ( | ||
| componentTheme: RangeInputTheme, | ||
| props: RangeInputProps | ||
| componentTheme: NewComponentTypes['RangeInput'], | ||
| props: RangeInputProps, | ||
| sharedTokens: SharedTokens | ||
| ): RangeInputStyle => { | ||
| const { size, thumbVariant } = props | ||
| const valueSizeVariants = { | ||
| small: { | ||
| fontSize: componentTheme.valueSmallFontSize, | ||
| padding: componentTheme.valueSmallPadding, | ||
| padding: `${'0 ' + componentTheme.valueSmallPadding}`, | ||
| lineHeight: componentTheme.valueSmallLineHeight | ||
| }, | ||
| medium: { | ||
| fontSize: componentTheme.valueMediumFontSize, | ||
| padding: componentTheme.valueMediumPadding, | ||
| padding: `${'0 ' + componentTheme.valueMediumPadding}`, | ||
| lineHeight: componentTheme.valueMediumLineHeight | ||
| }, | ||
| large: { | ||
| fontSize: componentTheme.valueLargeFontSize, | ||
| padding: componentTheme.valueLargePadding, | ||
| padding: `${'0 ' + componentTheme.valueLargePadding}`, | ||
| lineHeight: componentTheme.valueLargeLineHeight | ||
| } | ||
| } | ||
|
|
||
| const trackStyle = { | ||
| borderRadius: '0.312em', | ||
| borderColor: 'transparent', | ||
| borderWidth: '1px', | ||
| borderStyle: 'solid', | ||
| borderColor: componentTheme.trackBorderColor, | ||
| color: 'transparent', | ||
| cursor: 'pointer', | ||
| background: componentTheme.trackBackground, | ||
|
|
@@ -73,7 +78,7 @@ const generateStyle = ( | |
| deprecated: { | ||
| width: componentTheme.handleSize, | ||
| height: componentTheme.handleSize, | ||
| boxShadow: `0 0.0625rem 0 ${componentTheme.handleShadowColor}` | ||
| boxShadow: `0 0.0625rem 0 ${darken(componentTheme.handleShadowColor)}` | ||
| }, | ||
| accessible: { | ||
| width: borderedHandleSize, | ||
|
|
@@ -82,7 +87,7 @@ const generateStyle = ( | |
| borderColor: componentTheme.handleBorderColor, | ||
| borderStyle: 'solid', | ||
| boxSizing: 'border-box', | ||
| boxShadow: componentTheme.handleShadow | ||
| boxShadow: boxShadowObjectsToCSSString(componentTheme.boxShadow) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -101,25 +106,29 @@ const generateStyle = ( | |
|
|
||
| const thumbPosition = { | ||
| deprecated: { | ||
| marginTop: `calc(-1 * ${componentTheme.handleSize} / 4)` | ||
| marginTop: `calc(-1 * ${componentTheme.handleSize} / 4 - 1px)` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because the track got a '1px' wide border, the thumb position changed too so I adjusted the missing pixels here,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this feels a bit magic to me, maybe you could create a const for the borderwidth and use that above and here, also a comment like this would be good in the code |
||
| }, | ||
| accessible: { | ||
| marginTop: `calc(-1 * ${borderedHandleSize} / 4)` | ||
| marginTop: `calc(-1 * ${borderedHandleSize} / 4 - 1px)` | ||
| } | ||
| } | ||
|
|
||
| const thumbFocusActiveStyle = { | ||
| deprecated: { | ||
| background: componentTheme.handleFocusBackground, | ||
| boxShadow: `0 0.0625rem 0 ${componentTheme.handleShadowColor}, 0 0 0 ${componentTheme.handleFocusOutlineWidth} ${componentTheme.handleFocusOutlineColor}` | ||
| boxShadow: `0 0.0625rem 0 ${darken( | ||
| componentTheme.handleShadowColor | ||
| )}, 0 0 0 ${componentTheme.handleFocusOutlineWidth} ${alpha( | ||
| componentTheme.handleFocusOutlineColor, | ||
| 40 | ||
| )}` | ||
| }, | ||
| accessible: { | ||
| background: componentTheme.handleFocusBackground, | ||
| boxShadow: | ||
| componentTheme.handleShadow + | ||
| ', ' + | ||
| `${boxShadowObjectsToCSSString(componentTheme.boxShadow)}, ` + | ||
| `inset 0 0 0 ${componentTheme.handleFocusInset} ${componentTheme.handleFocusBackground}, ` + | ||
| `inset 0 0 0 calc(${componentTheme.handleFocusInset} + ${componentTheme.handleFocusRingSize}) ${componentTheme.handleFocusRingColor}` | ||
| `inset 0 0 0 calc(${componentTheme.handleFocusInset} + ${sharedTokens.focusOutline.width}) ${sharedTokens.focusOutline.onColor}` | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,20 +27,63 @@ import { TokenBoxshadowValueInst } from '../themes/newThemes/commonTypes' | |
| /** | ||
| * Converts a BoxShadowObject from Token Studio to a CSS box-shadow string | ||
| */ | ||
| function boxShadowObjectToString(boxShadowObject: TokenBoxshadowValueInst) { | ||
| function boxShadowToCSSString(boxShadowObject: TokenBoxshadowValueInst) { | ||
| // weird string concatenation is to make it look nice in the debugger | ||
|
Comment on lines
+30
to
+31
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this from this PR: #2282
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that one is merged now, please check if you have any conflicts |
||
| if (boxShadowObject.type === 'innerShadow') { | ||
| return `inset ${boxShadowObject.x} | ||
| ${boxShadowObject.y} | ||
| ${boxShadowObject.blur ? boxShadowObject.blur : ''} | ||
| ${boxShadowObject.spread ? boxShadowObject.spread : ''} | ||
| ${boxShadowObject.color}` | ||
| return ( | ||
| `inset ${boxShadowObject.x} ` + | ||
| `${boxShadowObject.y} ` + | ||
| `${boxShadowObject.blur ? boxShadowObject.blur : ''} ` + | ||
| `${boxShadowObject.spread ? boxShadowObject.spread : ''} ` + | ||
| `${boxShadowObject.color}` | ||
| ) | ||
| } | ||
| return `${boxShadowObject.x} | ||
| ${boxShadowObject.y} | ||
| ${boxShadowObject.blur ? boxShadowObject.blur : ''} | ||
| ${boxShadowObject.spread ? boxShadowObject.spread : ''} | ||
| ${boxShadowObject.color}` | ||
| return ( | ||
| `${boxShadowObject.x} ` + | ||
| `${boxShadowObject.y} ` + | ||
| `${boxShadowObject.blur ? boxShadowObject.blur : ''} ` + | ||
| `${boxShadowObject.spread ? boxShadowObject.spread : ''} ` + | ||
| `${boxShadowObject.color}` | ||
| ) | ||
| } | ||
|
|
||
| export default boxShadowObjectToString | ||
| export { boxShadowObjectToString } | ||
| function getShadowsInOrder( | ||
| shadowsObj: Record<string, TokenBoxshadowValueInst> | ||
| ) { | ||
| return Object.keys(shadowsObj) | ||
| .sort((a, b) => { | ||
| const numA = parseInt(a) | ||
| const numB = parseInt(b) | ||
| return numA - numB | ||
| }) | ||
| .map((key) => shadowsObj[key]) | ||
| } | ||
|
|
||
| /** | ||
| * Converts a box shadow object that looks like this: | ||
| * ``` | ||
| * { | ||
| * '1': {color: 'rgba(12, 0, 0, 0.2)', x:...}, | ||
| * '2': {color: 'rgba(0, 0, 0, 0.1)', x:...}, | ||
| * '0': {color: 'rgba(0, 0, 0, 0.1)', x:...} | ||
| * } | ||
| * ``` | ||
| * to a CSS box-shadow string e.g. | ||
| * ``` | ||
| * 0px 0.375rem 0.4375rem 0px rgba(12,0,0,0.2), | ||
| * 0px 0.625rem 1.75rem 0px rgba(0,0,0,0.1), | ||
| * 0px 0.625rem 1.75rem 0px rgba(0,0,0,0.1) | ||
| * ``` | ||
| */ | ||
| function boxShadowObjectsToCSSString( | ||
| shadowObject: Record<string, TokenBoxshadowValueInst> | ||
| ) { | ||
| const shadows = getShadowsInOrder(shadowObject) | ||
| let result = '' | ||
| for (const shadow of shadows) { | ||
| result += boxShadowToCSSString(shadow) + ',\n' | ||
| } | ||
| return result.slice(0, -2) | ||
| } | ||
|
|
||
| export { boxShadowToCSSString, boxShadowObjectsToCSSString } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you only want to set the right and left paddings, a better approach would be to use the paddingInline css prop so you don't have to set the top and bottom to 0