margo-ui 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/callout/style.ts +2 -3
- package/src/components/label/label.tsx +8 -3
- package/src/components/label/style.ts +3 -1
- package/src/components/label/type.ts +1 -0
- package/src/components/slider/slider.css +73 -0
- package/src/components/slider/slider.tsx +44 -0
- package/src/components/slider/style.ts +2 -0
- package/src/components/slider/type.ts +3 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export const calloutBaseClassName =
|
|
2
|
-
"space-y-2 rounded-margo-base border-l-margo border-primary bg-low px-4 py-3 text-on-main";
|
|
1
|
+
export const calloutBaseClassName = "rounded-margo-base border-l-margo border-primary bg-low px-4 py-3 text-on-main";
|
|
3
2
|
|
|
4
|
-
export const calloutTitleClassName = "block text-mc uppercase tracking-widest text-primary";
|
|
3
|
+
export const calloutTitleClassName = "block mb-1.5 text-mc uppercase tracking-widest text-primary";
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { Tag } from "react-renderable";
|
|
2
2
|
|
|
3
3
|
import { cn } from "../../utils/cn/cn.js";
|
|
4
|
-
import { labelBaseClassName, labelDisabledClassName } from "./style.js";
|
|
4
|
+
import { labelBaseClassName, labelDisabledClassName, labelSpacedClassName } from "./style.js";
|
|
5
5
|
|
|
6
6
|
import type { ElementType } from "react";
|
|
7
7
|
import type { LabelProps } from "./type.js";
|
|
8
8
|
|
|
9
|
-
export const Label = <T extends ElementType = "label">({
|
|
9
|
+
export const Label = <T extends ElementType = "label">({
|
|
10
|
+
disabled = false,
|
|
11
|
+
spaced = false,
|
|
12
|
+
className,
|
|
13
|
+
...rest
|
|
14
|
+
}: LabelProps<T>) => (
|
|
10
15
|
<Tag
|
|
11
16
|
{...Tag.forward<T>(rest, "label")}
|
|
12
17
|
data-margo-disabled={disabled}
|
|
13
|
-
className={cn(labelBaseClassName, disabled && labelDisabledClassName, className)}
|
|
18
|
+
className={cn(labelBaseClassName, spaced && labelSpacedClassName, disabled && labelDisabledClassName, className)}
|
|
14
19
|
/>
|
|
15
20
|
);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export const labelBaseClassName = "block text-mc uppercase tracking-widest text-medium truncate
|
|
1
|
+
export const labelBaseClassName = "block text-mc uppercase tracking-widest text-medium truncate";
|
|
2
|
+
|
|
3
|
+
export const labelSpacedClassName = "pl-3.5 mb-1";
|
|
2
4
|
|
|
3
5
|
export const labelDisabledClassName = "opacity-40";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
.margo-slider {
|
|
2
|
+
appearance: none;
|
|
3
|
+
|
|
4
|
+
--margo-slider-track: var(--margo-color-border);
|
|
5
|
+
--margo-slider-fill: var(--margo-color-primary);
|
|
6
|
+
--margo-slider-thumb: var(--margo-color-primary);
|
|
7
|
+
--margo-slider-thumb-border: var(--margo-color-primary-darken);
|
|
8
|
+
--margo-slider-thumb-size: 1rem;
|
|
9
|
+
--margo-slider-track-size: 0.375rem;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.margo-slider::-webkit-slider-runnable-track {
|
|
13
|
+
block-size: var(--margo-slider-track-size);
|
|
14
|
+
border-radius: 9999px;
|
|
15
|
+
background: linear-gradient(
|
|
16
|
+
to right,
|
|
17
|
+
var(--margo-slider-fill) var(--margo-slider-value, 0%),
|
|
18
|
+
var(--margo-slider-track) var(--margo-slider-value, 0%)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.margo-slider::-moz-range-track {
|
|
23
|
+
block-size: var(--margo-slider-track-size);
|
|
24
|
+
border-radius: 9999px;
|
|
25
|
+
background: var(--margo-slider-track);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.margo-slider::-moz-range-progress {
|
|
29
|
+
block-size: var(--margo-slider-track-size);
|
|
30
|
+
border-radius: 9999px;
|
|
31
|
+
background: var(--margo-slider-fill);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.margo-slider::-webkit-slider-thumb {
|
|
35
|
+
appearance: none;
|
|
36
|
+
inline-size: var(--margo-slider-thumb-size);
|
|
37
|
+
block-size: var(--margo-slider-thumb-size);
|
|
38
|
+
margin-block-start: calc((var(--margo-slider-track-size) - var(--margo-slider-thumb-size)) / 2);
|
|
39
|
+
border: var(--margo-border) solid var(--margo-slider-thumb-border);
|
|
40
|
+
border-radius: 9999px;
|
|
41
|
+
background-color: var(--margo-slider-thumb);
|
|
42
|
+
box-shadow: var(--margo-shadow-button);
|
|
43
|
+
transition: scale 120ms ease-out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.margo-slider::-moz-range-thumb {
|
|
47
|
+
inline-size: var(--margo-slider-thumb-size);
|
|
48
|
+
block-size: var(--margo-slider-thumb-size);
|
|
49
|
+
box-sizing: border-box;
|
|
50
|
+
border: var(--margo-border) solid var(--margo-slider-thumb-border);
|
|
51
|
+
border-radius: 9999px;
|
|
52
|
+
background-color: var(--margo-slider-thumb);
|
|
53
|
+
box-shadow: var(--margo-shadow-button);
|
|
54
|
+
transition: scale 120ms ease-out;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.margo-slider:enabled:active::-webkit-slider-thumb {
|
|
58
|
+
scale: 0.92;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.margo-slider:enabled:active::-moz-range-thumb {
|
|
62
|
+
scale: 0.92;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.margo-slider:focus-visible::-webkit-slider-thumb {
|
|
66
|
+
outline: var(--margo-border) solid var(--margo-color-on-main);
|
|
67
|
+
outline-offset: 1px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.margo-slider:focus-visible::-moz-range-thumb {
|
|
71
|
+
outline: var(--margo-border) solid var(--margo-color-on-main);
|
|
72
|
+
outline-offset: 1px;
|
|
73
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn/cn.js";
|
|
2
|
+
import { sliderBaseClassName } from "./style.js";
|
|
3
|
+
|
|
4
|
+
import type { ChangeEvent, CSSProperties } from "react";
|
|
5
|
+
import type { SliderProps } from "./type.js";
|
|
6
|
+
|
|
7
|
+
import "./slider.css";
|
|
8
|
+
|
|
9
|
+
const sliderPercent = (value: number, min: number, max: number) =>
|
|
10
|
+
max > min ? `${((Math.min(max, Math.max(min, value)) - min) / (max - min)) * 100}%` : "0%";
|
|
11
|
+
|
|
12
|
+
export const Slider = ({
|
|
13
|
+
min = 0,
|
|
14
|
+
max = 100,
|
|
15
|
+
value,
|
|
16
|
+
defaultValue,
|
|
17
|
+
style,
|
|
18
|
+
className,
|
|
19
|
+
onChange,
|
|
20
|
+
...rest
|
|
21
|
+
}: SliderProps) => {
|
|
22
|
+
const current = Number(value ?? defaultValue ?? (Number(min) + Number(max)) / 2);
|
|
23
|
+
|
|
24
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
25
|
+
const input = event.currentTarget;
|
|
26
|
+
|
|
27
|
+
input.style.setProperty("--margo-slider-value", sliderPercent(input.valueAsNumber, Number(min), Number(max)));
|
|
28
|
+
onChange?.(event);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<input
|
|
33
|
+
{...rest}
|
|
34
|
+
type="range"
|
|
35
|
+
min={min}
|
|
36
|
+
max={max}
|
|
37
|
+
value={value}
|
|
38
|
+
defaultValue={defaultValue}
|
|
39
|
+
onChange={handleChange}
|
|
40
|
+
style={{ ...style, "--margo-slider-value": sliderPercent(current, Number(min), Number(max)) } as CSSProperties}
|
|
41
|
+
className={cn(sliderBaseClassName, className)}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { Table } from "./components/table/table.js";
|
|
|
18
18
|
export { Toggle } from "./components/toggle/toggle.js";
|
|
19
19
|
export { Select } from "./components/select/select.js";
|
|
20
20
|
export { Sheet } from "./components/sheet/sheet.js";
|
|
21
|
+
export { Slider } from "./components/slider/slider.js";
|
|
21
22
|
export { TextArea } from "./components/text_area/text_area.js";
|
|
22
23
|
export { Spinner } from "./components/spinner/spinner.js";
|
|
23
24
|
export { Tooltip } from "./components/tooltip/tooltip.js";
|
|
@@ -81,6 +82,7 @@ export type {
|
|
|
81
82
|
} from "./components/table/type.js";
|
|
82
83
|
export type { SelectOwnProps, SelectProps } from "./components/select/type.js";
|
|
83
84
|
export type { SheetBodyProps, SheetFooterProps, SheetPlacement, SheetProps } from "./components/sheet/type.js";
|
|
85
|
+
export type { SliderProps } from "./components/slider/type.js";
|
|
84
86
|
export type { SpinnerProps } from "./components/spinner/type.js";
|
|
85
87
|
export type { TextAreaOwnProps, TextAreaProps, TextAreaTextProps } from "./components/text_area/type.js";
|
|
86
88
|
export type { ToggleProps } from "./components/toggle/type.js";
|