Skip to content

Commit

Permalink
Range input (viamrobotics#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
DTCurrie authored Dec 20, 2023
1 parent 653d0b8 commit 7fcb3e5
Show file tree
Hide file tree
Showing 14 changed files with 752 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LngLat } from 'maplibre-gl';
export let label: string | undefined = undefined;
/** Whether the inputs are readonly. */
export let readonly: boolean | undefined = undefined;
export let readonly = false;
/** The longitude value. */
export let lng: number | undefined = undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Install [Tailwind][]. In the `tailwind.config.js`, add the components to the con

```js
import { theme } from '@viamrobotics/prime-core/theme';
import { plugins } from '@viamrobotics/prime-core/plugins';

/** @type {import('tailwindcss').Config} */
export default {
Expand All @@ -24,7 +25,7 @@ export default {
'./node_modules/@viamrobotics/prime-core/**/*.{ts,svelte}',
],
theme,
plugins: [],
plugins,
};
```

Expand Down
5 changes: 3 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
"types": "./dist/index.d.ts",
"svelte": "./dist/index.js"
},
"./theme": "./theme.ts",
"./prime.css": "./prime.css"
"./prime.css": "./prime.css",
"./plugins": "./plugins.ts",
"./theme": "./theme.ts"
},
"files": [
"dist",
Expand Down
236 changes: 235 additions & 1 deletion packages/core/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const plugins = [
},
}),
},
{ values: theme('spacing') }
{ values: theme('width') }
);

matchUtilities(
Expand Down Expand Up @@ -83,5 +83,239 @@ export const plugins = [
},
{ values: theme('borderColor') }
);

matchUtilities(
{
'slider-track': (value: string) => ({
'&::-webkit-slider-runnable-track': {
background: value,
},
'&::-moz-range-track': {
background: value,
},
'&::-ms-track': {
background: 'transparent',
},
'&::-ms-fill-lower': {
background: value,
},
'&::-ms-fill-upper': {
background: value,
},
}),
},
{ values: theme('colors') }
);

matchUtilities(
{
'slider-track-w': (value: string) => ({
'&::-webkit-slider-runnable-track': {
width: value,
},
'&::-moz-range-track': {
width: value,
},
'&::-ms-track': {
width: value,
},
}),
},
{ values: theme('width') }
);

matchUtilities(
{
'slider-track-h': (value: string) => ({
'&::-webkit-slider-runnable-track': {
height: value,
},
'&::-moz-range-track': {
height: value,
},
'&::-ms-track': {
height: value,
},
}),
},
{ values: theme('height') }
);

matchUtilities(
{
'slider-track-cursor': (value: string) => ({
'&::-webkit-slider-runnable-track': {
cursor: value,
},
'&::-moz-range-track': {
cursor: value,
},
'&::-ms-track': {
cursor: value,
},
}),
},
{ values: theme('cursor') }
);

matchUtilities(
{
'slider-thumb': (value: string) => ({
'&::-webkit-slider-thumb': {
background: value,
},
'&::-moz-range-thumb': {
background: value,
},
'&::-ms-thumb': {
background: value,
},
}),
},
{
values: {
...theme('backgroundColor'),
},
}
);

matchUtilities(
{
'slider-thumb-w': (value: string) => ({
'&::-webkit-slider-thumb': {
width: value,
},
'&::-moz-range-thumb': {
width: value,
},
'&::-ms-thumb': {
width: value,
},
}),
},
{ values: theme('width') }
);

matchUtilities(
{
'slider-thumb-h': (value: string) => ({
'&::-webkit-slider-thumb': {
height: value,
marginTop: `calc(-${value} / 2)`,
},
'&::-moz-range-thumb': {
height: value,
},
'&::-ms-thumb': {
height: value,
},
}),
},
{ values: theme('height') }
);

/*
* The default border properties were causing rendering issues, so we
* split the width utility into it's own class to avoid that
*/
matchUtilities(
{
'slider-thumb-border': (value: string) => ({
'&::-webkit-slider-thumb': {
borderWidth: value,
},
'&::-moz-range-thumb': {
borderWidth: value,
},
'&::-ms-thumb': {
borderWidth: value,
},
}),
},
{ values: theme('borderWidth') }
);

matchUtilities(
{
'slider-thumb-border': (value: string) => ({
'&::-webkit-slider-thumb': {
borderStyle: value,
},
'&::-moz-range-thumb': {
borderStyle: value,
},
'&::-ms-thumb': {
borderStyle: value,
},
}),
},
{
values: {
DEFAULT: 'solid',
solid: 'solid',
dashed: 'dashed',
dotted: 'dotted',
double: 'double',
},
}
);

matchUtilities(
{
'slider-thumb-border': (value: string) => ({
'&::-webkit-slider-thumb': {
borderColor: value,
},
'&::-moz-range-thumb': {
borderColor: value,
},
'&::-ms-thumb': {
borderColor: value,
},
}),
},
{
values: {
...theme('borderColor'),
DEFAULT: theme('borderColor.light'),
},
}
);

matchUtilities(
{
'slider-thumb-border': (value: string) => ({
'&::-webkit-slider-thumb': {
borderRadius: value,
},
'&::-moz-range-thumb': {
borderRadius: value,
},
'&::-ms-thumb': {
borderRadius: value,
},
}),
},
{
values: { ...theme('borderRadius'), DEFAULT: '9999px' },
}
);

matchUtilities(
{
'slider-thumb-cursor': (value: string) => ({
'&::-webkit-slider-thumb': {
cursor: value,
},
'&::-moz-range-thumb': {
cursor: value,
},
'&::-ms-thumb': {
cursor: value,
},
}),
},
{ values: theme('cursor') }
);
}),
] satisfies OptionalConfig['plugins'];
1 change: 1 addition & 0 deletions packages/core/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type { IconName } from './icon/icons';
export {
Input,
NumericInput,
RangeInput,
RestrictedTextInput,
SliderInput,
TextInput,
Expand Down
Loading

0 comments on commit 7fcb3e5

Please sign in to comment.