@propellerads/time-picker 3.0.2 → 4.0.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/README.md +88 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +25 -3
- package/dist/index.js +37 -56
- package/dist/index.js.map +1 -1
- package/package.json +18 -8
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# TimePicker
|
|
2
|
+
|
|
3
|
+
A time of day, `HH:mm`, in the box of [Input](../Input/README.md): the same
|
|
4
|
+
height, contour, focus ring and messages as every field beside it. The time is
|
|
5
|
+
typed, and the arrow keys step the hour or the minutes; Chrome's clock button is
|
|
6
|
+
hidden, as in shadcn's time field, and a phone opens its own wheel on a tap. A
|
|
7
|
+
grey clock at the end of the box, after the field's mark, says what the field
|
|
8
|
+
holds; it is not a button, and a press on it puts the caret in the field.
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
[NPM](https://www.npmjs.com/package/@propellerads/time-picker) |
|
|
13
|
+
[Github](https://github.com/propellerads/ui-components/tree/master/Components/TimePicker)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
bun add @propellerads/time-picker
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The built entry imports its own stylesheet. The tokens are the app's:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import '@propellerads/tokens/common.css';
|
|
25
|
+
import '@propellerads/tokens/propellerads.css'; // or monetag / propush / zeydoo
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Use
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import TimePicker from '@propellerads/time-picker';
|
|
32
|
+
|
|
33
|
+
<TimePicker
|
|
34
|
+
elementId="start-time"
|
|
35
|
+
label="Start time"
|
|
36
|
+
value={time}
|
|
37
|
+
onChange={setTime}
|
|
38
|
+
minTime="06:00"
|
|
39
|
+
maxTime="18:45"
|
|
40
|
+
error={isTooEarly ? 'Starts no earlier than 10:00' : undefined}
|
|
41
|
+
/>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The label, the hint, the warning and the error work as on Input — see
|
|
45
|
+
[Label and messages](../Input/README.md#label-and-messages): `labelPosition` on
|
|
46
|
+
top, on the left or hidden; one message, the error before the warning before
|
|
47
|
+
the description; `messageDisplay` `compact` (the default, a mark at the end of
|
|
48
|
+
the field) or `line` (under it). The label keeps its colour.
|
|
49
|
+
|
|
50
|
+
`elementId` is the id of the time input, so a label written by the form —
|
|
51
|
+
`<Label for="start-time" />` — points at it, and a click focuses the time.
|
|
52
|
+
|
|
53
|
+
A time outside `minTime`–`maxTime` typed in is brought inside on blur.
|
|
54
|
+
|
|
55
|
+
## Props
|
|
56
|
+
|
|
57
|
+
| Prop | Type | Default | What it does |
|
|
58
|
+
|------------------|---------------------------------|-------------|--------------------------------------------------------------|
|
|
59
|
+
| `elementId` | `string` | | The id of the time input |
|
|
60
|
+
| `value` | `string` | | The time, `HH:mm` |
|
|
61
|
+
| `onChange` | `(value: string) => void` | | Called with the time |
|
|
62
|
+
| `minTime` | `string` | `'00:00'` | The earliest time |
|
|
63
|
+
| `maxTime` | `string` | `'23:59'` | The latest time |
|
|
64
|
+
| `label` | `ReactNode` | | The name of the field |
|
|
65
|
+
| `labelPosition` | `'top' \| 'left' \| 'hidden'` | `'top'` | Where the label stands |
|
|
66
|
+
| `optional` | `boolean` | `false` | Adds "(Optional)" after the label |
|
|
67
|
+
| `isRequired` | `boolean` | `false` | Sets `required`, with no mark |
|
|
68
|
+
| `messageDisplay` | `'compact' \| 'line'` | `'compact'` | Behind a mark at the end, or under the field |
|
|
69
|
+
| `description` | `ReactNode` | | What the field is for |
|
|
70
|
+
| `warning` | `string \| string[]` | | Allowed, but worth a second look; the contour turns yellow |
|
|
71
|
+
| `error` | `string \| string[]` | | What is wrong; the contour turns red |
|
|
72
|
+
| `isDisabled` | `boolean` | `false` | Switches the field off |
|
|
73
|
+
| `isReadonly` | `boolean` | `false` | Deprecated: `isDisabled`. Switches the field off, as before |
|
|
74
|
+
| `errors` | `string[]` | | Deprecated: `error` |
|
|
75
|
+
| `showErrorLabel` | `boolean` | | Deprecated: the error is always shown |
|
|
76
|
+
|
|
77
|
+
## From v3
|
|
78
|
+
|
|
79
|
+
- The field is Input's box on the tokens. styled-components,
|
|
80
|
+
`@propellerads/stylevariables` and `@propellerads/theme-annotation` are no
|
|
81
|
+
longer needed, and a styled-components theme no longer reaches the field.
|
|
82
|
+
- The id of the input is `elementId`, not `${elementId}-input-time`, so a label
|
|
83
|
+
of the form that points at `elementId` focuses the time.
|
|
84
|
+
- `isRequired` sets `required` and draws no asterisk: the optional fields are the
|
|
85
|
+
ones marked.
|
|
86
|
+
- `errors` are shown whenever they are given, behind the `!` mark or under the
|
|
87
|
+
field; `showErrorLabel` does nothing.
|
|
88
|
+
- The box hugs the time instead of being 82px wide.
|
package/dist/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.input-group.time-picker{inline-size:fit-content}.time-picker .input-group__control::-webkit-calendar-picker-indicator{appearance:none;display:none}.time-picker__icon{color:var(--color-quiet-text);flex:none;order:1}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { InputProps } from '@propellerads/input';
|
|
2
3
|
import { ReactNode } from 'react';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
/** The props of the field around the time, as `Input` has them. */
|
|
6
|
+
type FieldProps = Pick<InputProps, 'labelPosition' | 'labelWidth' | 'optional' | 'optionalText' | 'messageDisplay' | 'description' | 'error' | 'warning' | 'hintLabel' | 'aria-label'>;
|
|
7
|
+
type TimePickerProps = FieldProps & {
|
|
8
|
+
/** The id of the time input. A label elsewhere on the page points at it with `for`. */
|
|
5
9
|
elementId: string;
|
|
10
|
+
/** Called with the time as `HH:mm`. */
|
|
6
11
|
onChange: (value: string) => void;
|
|
12
|
+
/** The time as `HH:mm`. */
|
|
7
13
|
value: string;
|
|
14
|
+
/** The earliest time; an earlier one typed in is brought up to it on blur. @default '00:00' */
|
|
8
15
|
minTime?: string;
|
|
16
|
+
/** The latest time; a later one typed in is brought down to it on blur. @default '23:59' */
|
|
9
17
|
maxTime?: string;
|
|
18
|
+
/** The name of the field. */
|
|
10
19
|
label?: ReactNode;
|
|
11
|
-
|
|
20
|
+
/** Sets `required` on the input. No asterisk: the optional fields are the ones marked. */
|
|
12
21
|
isRequired?: boolean;
|
|
22
|
+
/** Switches the field off. */
|
|
23
|
+
isDisabled?: boolean;
|
|
24
|
+
/** @deprecated Use `isDisabled`. Switches the field off, as it always did. */
|
|
13
25
|
isReadonly?: boolean;
|
|
26
|
+
/** @deprecated Use `error`. */
|
|
27
|
+
errors?: string[];
|
|
28
|
+
/** @deprecated The error is always shown now; `messageDisplay` says how. */
|
|
14
29
|
showErrorLabel?: boolean;
|
|
15
30
|
};
|
|
16
31
|
|
|
17
|
-
|
|
32
|
+
/**
|
|
33
|
+
* A time of day, `HH:mm`, in the box of Input: the same height, contour, focus
|
|
34
|
+
* ring and messages as every field next to it. The browser draws the hours and
|
|
35
|
+
* the minutes; its clock button is hidden in time-picker.css, as in shadcn's
|
|
36
|
+
* time field: the time is typed, and a phone opens its own wheel on a tap. The
|
|
37
|
+
* clock at the end is a picture of what the field holds.
|
|
38
|
+
*/
|
|
39
|
+
declare const TimePicker: ({ elementId, onChange, value, minTime, maxTime, label, isRequired, isDisabled, isReadonly, errors, showErrorLabel: _showErrorLabel, error, ...field }: TimePickerProps) => react_jsx_runtime.JSX.Element;
|
|
18
40
|
|
|
19
41
|
export { TimePicker as default };
|
|
20
42
|
export type { TimePickerProps };
|
package/dist/index.js
CHANGED
|
@@ -1,62 +1,43 @@
|
|
|
1
|
-
import e from "@propellerads/
|
|
2
|
-
import t from "
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
&[disabled] {
|
|
21
|
-
background-color: ${a};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
${({ $hasErrors: e }) => e && `
|
|
25
|
-
border: 1px solid ${r} !important;
|
|
26
|
-
color: ${r};
|
|
27
|
-
|
|
28
|
-
&::-webkit-calendar-picker-indicator {
|
|
29
|
-
filter: invert(22%) sepia(63%) saturate(7197%) hue-rotate(353deg) brightness(106%) contrast(87%);
|
|
30
|
-
}
|
|
31
|
-
`}
|
|
32
|
-
`, p = n.div`
|
|
33
|
-
position: absolute;
|
|
34
|
-
right: 1px;
|
|
35
|
-
top: calc(50% - ${o * 2.5}px);
|
|
36
|
-
`, m = "00:00", h = "23:59", g = ({ elementId: n, onChange: r, errors: i, value: a, minTime: o = m, maxTime: s = h, label: g, isRequired: _ = !1, isReadonly: v = !1, showErrorLabel: y }) => {
|
|
37
|
-
let b = !!i?.length, x = (e) => {
|
|
1
|
+
import e from "@propellerads/input";
|
|
2
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
3
|
+
import './index.css';//#region src/index.tsx
|
|
4
|
+
var n = "00:00", r = "23:59", i = (e) => {
|
|
5
|
+
let t = e.currentTarget.closest(".input-group")?.querySelector("input:not(:disabled)");
|
|
6
|
+
t != null && (e.preventDefault(), t.focus());
|
|
7
|
+
}, a = () => /* @__PURE__ */ t("svg", {
|
|
8
|
+
className: "time-picker__icon",
|
|
9
|
+
viewBox: "0 0 24 24",
|
|
10
|
+
width: "20",
|
|
11
|
+
height: "20",
|
|
12
|
+
"aria-hidden": "true",
|
|
13
|
+
onMouseDown: i,
|
|
14
|
+
children: /* @__PURE__ */ t("path", {
|
|
15
|
+
fill: "currentColor",
|
|
16
|
+
d: "M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm-.22-13h-.06c-.4 0-.72.32-.72.72v4.72c0 .35.18.68.49.86l4.15 2.49c.34.2.78.1.98-.24.21-.34.1-.79-.25-.99l-3.87-2.3V7.72c0-.4-.32-.72-.72-.72z"
|
|
17
|
+
})
|
|
18
|
+
}), o = ({ elementId: i, onChange: o, value: s, minTime: c = n, maxTime: l = r, label: u, isRequired: d = !1, isDisabled: f, isReadonly: p = !1, errors: m, showErrorLabel: h, error: g, ..._ }) => {
|
|
19
|
+
let v = (e) => {
|
|
38
20
|
let { value: t } = e.target;
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
return /* @__PURE__ */
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
required: _
|
|
45
|
-
}), /* @__PURE__ */ u(d, { children: [/* @__PURE__ */ l(f, {
|
|
46
|
-
id: S,
|
|
47
|
-
$hasErrors: b,
|
|
48
|
-
required: _,
|
|
49
|
-
disabled: v,
|
|
50
|
-
onChange: (e) => r(e.target.value),
|
|
51
|
-
onBlur: x,
|
|
21
|
+
o(t < c ? c : t > l ? l : t);
|
|
22
|
+
}, y = g ?? (m !== void 0 && m.length > 0 ? m : void 0);
|
|
23
|
+
return /* @__PURE__ */ t(e, {
|
|
24
|
+
..._,
|
|
25
|
+
id: i,
|
|
52
26
|
type: "time",
|
|
53
|
-
value:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
27
|
+
value: s,
|
|
28
|
+
min: c,
|
|
29
|
+
max: l,
|
|
30
|
+
onChange: (e) => o(e.target.value),
|
|
31
|
+
onBlur: v,
|
|
32
|
+
endAddon: /* @__PURE__ */ t(a, {}),
|
|
33
|
+
isDisabled: f ?? p,
|
|
34
|
+
isRequired: d,
|
|
35
|
+
groupClassName: "time-picker",
|
|
36
|
+
label: u,
|
|
37
|
+
error: y
|
|
38
|
+
});
|
|
58
39
|
};
|
|
59
40
|
//#endregion
|
|
60
|
-
export {
|
|
41
|
+
export { o as default };
|
|
61
42
|
|
|
62
43
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.tsx"],"sourcesContent":["import Input from '@propellerads/input';\nimport type {FocusEventHandler, MouseEvent} from 'react';\nimport './time-picker.css';\nimport type {TimePickerProps} from './types';\n\nconst DEFAULT_MIN_TIME = '00:00' as const;\nconst DEFAULT_MAX_TIME = '23:59' as const;\n\n/**\n * A press on the clock is a press on the field: the input takes the focus, and\n * the time is typed. The mouse-down is held back, or it would take the focus\n * away first.\n */\nconst pressField = (event: MouseEvent<SVGSVGElement>) => {\n const input = event.currentTarget.closest('.input-group')?.querySelector<HTMLInputElement>('input:not(:disabled)');\n if (input == null) {\n return;\n }\n event.preventDefault();\n input.focus();\n};\n\n/**\n * The clock of @propellerads/icon's `Time`, drawn here so the package does not\n * take styled-components with it. It only says what the field is: it is not a\n * button and a screen reader skips it; a press on it is a press on the field.\n */\nconst TimeIcon = () => (\n <svg\n className=\"time-picker__icon\"\n viewBox=\"0 0 24 24\"\n width=\"20\"\n height=\"20\"\n aria-hidden=\"true\"\n onMouseDown={pressField}\n >\n <path\n fill=\"currentColor\"\n d=\"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm-.22-13h-.06c-.4 0-.72.32-.72.72v4.72c0 .35.18.68.49.86l4.15 2.49c.34.2.78.1.98-.24.21-.34.1-.79-.25-.99l-3.87-2.3V7.72c0-.4-.32-.72-.72-.72z\"\n />\n </svg>\n);\n\n/**\n * A time of day, `HH:mm`, in the box of Input: the same height, contour, focus\n * ring and messages as every field next to it. The browser draws the hours and\n * the minutes; its clock button is hidden in time-picker.css, as in shadcn's\n * time field: the time is typed, and a phone opens its own wheel on a tap. The\n * clock at the end is a picture of what the field holds.\n */\nconst TimePicker = ({\n elementId,\n onChange,\n value,\n minTime = DEFAULT_MIN_TIME,\n maxTime = DEFAULT_MAX_TIME,\n label,\n isRequired = false,\n isDisabled,\n isReadonly = false,\n errors,\n showErrorLabel: _showErrorLabel,\n error,\n ...field\n}: TimePickerProps) => {\n const onBlurCorrectTime: FocusEventHandler<HTMLInputElement> = (event) => {\n const {value: nextValue} = event.target;\n const correctTime = nextValue < minTime ? minTime : nextValue > maxTime ? maxTime : nextValue;\n\n onChange(correctTime);\n };\n\n // The old errors become the field's error. The key is passed even when there\n // is none, so the field stays put while an error comes and goes.\n const fieldError = error ?? (errors !== undefined && errors.length > 0 ? errors : undefined);\n\n return (\n <Input\n {...field}\n // The id is the one a label elsewhere on the page points at.\n id={elementId}\n type=\"time\"\n value={value}\n min={minTime}\n max={maxTime}\n onChange={(event) => onChange(event.target.value)}\n onBlur={onBlurCorrectTime}\n endAddon={<TimeIcon />}\n isDisabled={isDisabled ?? isReadonly}\n isRequired={isRequired}\n groupClassName=\"time-picker\"\n // An empty label draws none, as before: Label leaves it out.\n label={label}\n error={fieldError}\n />\n );\n};\n\nexport default TimePicker;\nexport type {TimePickerProps} from './types';\n"],"mappings":";;;AAKA,IAAM,IAAmB,SACnB,IAAmB,SAOnB,KAAc,MAAqC;CACvD,IAAM,IAAQ,EAAM,cAAc,QAAQ,eAAe,EAAE,cAAgC,uBAAuB;CAC9G,KAAS,SAGb,EAAM,gBAAgB,EACtB,EAAM,OAAO;GAQT,UACJ,kBAAC,OAAD;CACE,WAAU;CACV,SAAQ;CACR,OAAM;CACN,QAAO;CACP,eAAY;CACZ,aAAa;WAEb,kBAAC,QAAD;EACE,MAAK;EACL,GAAE;EACF,CAAA;CACE,CAAA,EAUF,KAAc,EAClB,cACA,aACA,UACA,aAAU,GACV,aAAU,GACV,UACA,gBAAa,IACb,eACA,gBAAa,IACb,WACA,gBAAgB,GAChB,UACA,GAAG,QACkB;CACrB,IAAM,KAA0D,MAAU;EACxE,IAAM,EAAC,OAAO,MAAa,EAAM;EAGjC,EAFoB,IAAY,IAAU,IAAU,IAAY,IAAU,IAAU,EAE/D;IAKjB,IAAa,MAAU,MAAW,KAAA,KAAa,EAAO,SAAS,IAAI,IAAS,KAAA;CAElF,OACE,kBAAC,GAAD;EACE,GAAI;EAEJ,IAAI;EACJ,MAAK;EACE;EACP,KAAK;EACL,KAAK;EACL,WAAW,MAAU,EAAS,EAAM,OAAO,MAAM;EACjD,QAAQ;EACR,UAAU,kBAAC,GAAD,EAAY,CAAA;EACtB,YAAY,KAAc;EACd;EACZ,gBAAe;EAER;EACP,OAAO;EACP,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@propellerads/time-picker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
|
+
"style": "dist/index.css",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
9
|
"types": "./dist/index.d.ts",
|
|
9
10
|
"import": "./dist/index.js"
|
|
10
|
-
}
|
|
11
|
+
},
|
|
12
|
+
"./index.css": "./dist/index.css"
|
|
11
13
|
},
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"**/*.css"
|
|
16
|
+
],
|
|
12
17
|
"files": [
|
|
13
18
|
"dist"
|
|
14
19
|
],
|
|
@@ -24,21 +29,26 @@
|
|
|
24
29
|
"homepage": "https://github.com/propellerads/ui-components#readme",
|
|
25
30
|
"private": false,
|
|
26
31
|
"dependencies": {
|
|
27
|
-
"@propellerads/
|
|
28
|
-
"@propellerads/label": "^5.0.0",
|
|
29
|
-
"@propellerads/stylevariables": "^2.0.2",
|
|
30
|
-
"@propellerads/theme-annotation": "^2.1.1"
|
|
32
|
+
"@propellerads/input": "^2.1.0"
|
|
31
33
|
},
|
|
32
34
|
"peerDependencies": {
|
|
35
|
+
"@propellerads/tokens": ">=0.4.0",
|
|
33
36
|
"react": "^18.0.0 || ^19.0.0",
|
|
34
|
-
"
|
|
37
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@propellerads/tokens": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
35
43
|
},
|
|
36
44
|
"devDependencies": {
|
|
45
|
+
"@propellerads/tokens": "workspace:^",
|
|
37
46
|
"@types/react": "^19.2.14",
|
|
38
47
|
"@vitejs/plugin-react": "^6.0.1",
|
|
39
48
|
"rollup": "^4.60.3",
|
|
40
49
|
"rollup-plugin-dts": "^6.4.1",
|
|
41
50
|
"typescript": "^6.0.3",
|
|
42
|
-
"vite": "^8.0.11"
|
|
51
|
+
"vite": "^8.0.11",
|
|
52
|
+
"vite-plugin-lib-inject-css": "^2.2.2"
|
|
43
53
|
}
|
|
44
54
|
}
|