@cocso-ui/react 1.11.0 → 1.12.1
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/dist/cjs/components/breadcrumb/breadcrumb.d.ts +24 -3
- package/dist/cjs/components/breadcrumb/breadcrumb.js +44 -2
- package/dist/cjs/components/breadcrumb/breadcrumb.module.css.js +2 -2
- package/dist/cjs/components/card/card.d.ts +49 -2
- package/dist/cjs/components/card/card.js +76 -10
- package/dist/cjs/components/card/card.module.css.js +2 -2
- package/dist/cjs/components/copy-button/copy-button.d.ts +29 -0
- package/dist/cjs/components/copy-button/copy-button.js +67 -0
- package/dist/cjs/components/empty-state/empty-state.d.ts +30 -0
- package/dist/cjs/components/empty-state/empty-state.js +50 -0
- package/dist/cjs/components/empty-state/empty-state.module.css.js +9 -0
- package/dist/cjs/components/file-uploader/file-uploader.d.ts +80 -0
- package/dist/cjs/components/file-uploader/file-uploader.js +258 -0
- package/dist/cjs/components/file-uploader/file-uploader.module.css.js +9 -0
- package/dist/cjs/components/form-field/form-field-context.d.ts +31 -0
- package/dist/cjs/components/form-field/form-field-context.js +53 -0
- package/dist/cjs/components/form-field/form-field-parts.d.ts +52 -0
- package/dist/cjs/components/form-field/form-field-parts.js +109 -0
- package/dist/cjs/components/form-field/form-field.d.ts +44 -0
- package/dist/cjs/components/form-field/form-field.js +61 -0
- package/dist/cjs/components/form-field/form-field.module.css.js +9 -0
- package/dist/cjs/components/info-popover/info-popover.d.ts +43 -0
- package/dist/cjs/components/info-popover/info-popover.js +57 -0
- package/dist/cjs/components/info-popover/info-popover.module.css.js +9 -0
- package/dist/cjs/components/loading-overlay/loading-overlay.d.ts +33 -0
- package/dist/cjs/components/loading-overlay/loading-overlay.js +68 -0
- package/dist/cjs/components/loading-overlay/loading-overlay.module.css.js +9 -0
- package/dist/cjs/components/number-input/number-input.d.ts +39 -0
- package/dist/cjs/components/number-input/number-input.js +167 -0
- package/dist/cjs/components/section-header/section-header.d.ts +48 -0
- package/dist/cjs/components/section-header/section-header.js +210 -0
- package/dist/cjs/components/section-header/section-header.module.css.js +9 -0
- package/dist/cjs/components/segmented-control/segmented-control.d.ts +55 -0
- package/dist/cjs/components/segmented-control/segmented-control.js +119 -0
- package/dist/cjs/components/segmented-control/segmented-control.module.css.js +9 -0
- package/dist/cjs/components/selection-chip/selection-chip.d.ts +22 -0
- package/dist/cjs/components/selection-chip/selection-chip.js +32 -0
- package/dist/cjs/components/selection-chip/selection-chip.module.css.js +9 -0
- package/dist/cjs/components/skeleton/skeleton.d.ts +7 -1
- package/dist/cjs/components/skeleton/skeleton.js +20 -2
- package/dist/cjs/components/skeleton/skeleton.module.css.js +1 -1
- package/dist/cjs/components/summary-card/summary-card.d.ts +47 -0
- package/dist/cjs/components/summary-card/summary-card.js +89 -0
- package/dist/cjs/components/summary-card/summary-card.module.css.js +9 -0
- package/dist/cjs/index.d.ts +15 -2
- package/dist/cjs/index.js +24 -0
- package/dist/esm/components/breadcrumb/breadcrumb.d.mts +24 -3
- package/dist/esm/components/breadcrumb/breadcrumb.mjs +44 -2
- package/dist/esm/components/breadcrumb/breadcrumb.module.css.mjs +1 -1
- package/dist/esm/components/card/card.d.mts +49 -2
- package/dist/esm/components/card/card.mjs +76 -10
- package/dist/esm/components/card/card.module.css.mjs +1 -1
- package/dist/esm/components/copy-button/copy-button.d.mts +29 -0
- package/dist/esm/components/copy-button/copy-button.mjs +65 -0
- package/dist/esm/components/empty-state/empty-state.d.mts +30 -0
- package/dist/esm/components/empty-state/empty-state.mjs +48 -0
- package/dist/esm/components/empty-state/empty-state.module.css.mjs +3 -0
- package/dist/esm/components/file-uploader/file-uploader.d.mts +80 -0
- package/dist/esm/components/file-uploader/file-uploader.mjs +256 -0
- package/dist/esm/components/file-uploader/file-uploader.module.css.mjs +3 -0
- package/dist/esm/components/form-field/form-field-context.d.mts +31 -0
- package/dist/esm/components/form-field/form-field-context.mjs +49 -0
- package/dist/esm/components/form-field/form-field-parts.d.mts +52 -0
- package/dist/esm/components/form-field/form-field-parts.mjs +105 -0
- package/dist/esm/components/form-field/form-field.d.mts +44 -0
- package/dist/esm/components/form-field/form-field.mjs +59 -0
- package/dist/esm/components/form-field/form-field.module.css.mjs +3 -0
- package/dist/esm/components/info-popover/info-popover.d.mts +43 -0
- package/dist/esm/components/info-popover/info-popover.mjs +55 -0
- package/dist/esm/components/info-popover/info-popover.module.css.mjs +3 -0
- package/dist/esm/components/loading-overlay/loading-overlay.d.mts +33 -0
- package/dist/esm/components/loading-overlay/loading-overlay.mjs +66 -0
- package/dist/esm/components/loading-overlay/loading-overlay.module.css.mjs +3 -0
- package/dist/esm/components/number-input/number-input.d.mts +39 -0
- package/dist/esm/components/number-input/number-input.mjs +165 -0
- package/dist/esm/components/section-header/section-header.d.mts +48 -0
- package/dist/esm/components/section-header/section-header.mjs +208 -0
- package/dist/esm/components/section-header/section-header.module.css.mjs +3 -0
- package/dist/esm/components/segmented-control/segmented-control.d.mts +55 -0
- package/dist/esm/components/segmented-control/segmented-control.mjs +117 -0
- package/dist/esm/components/segmented-control/segmented-control.module.css.mjs +3 -0
- package/dist/esm/components/selection-chip/selection-chip.d.mts +22 -0
- package/dist/esm/components/selection-chip/selection-chip.mjs +30 -0
- package/dist/esm/components/selection-chip/selection-chip.module.css.mjs +3 -0
- package/dist/esm/components/skeleton/skeleton.d.mts +7 -1
- package/dist/esm/components/skeleton/skeleton.mjs +20 -2
- package/dist/esm/components/summary-card/summary-card.d.mts +47 -0
- package/dist/esm/components/summary-card/summary-card.mjs +87 -0
- package/dist/esm/components/summary-card/summary-card.module.css.mjs +3 -0
- package/dist/esm/index.css +2 -2
- package/dist/esm/index.d.mts +15 -2
- package/dist/esm/index.mjs +12 -0
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var reactIcons = require('@cocso-ui/react-icons');
|
|
5
|
+
var cn = require('../../cn.js');
|
|
6
|
+
var infoPopover_module = require('./info-popover.module.css.js');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var popover = require('../popover/popover.js');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An info icon that folds away an explanation that never changes — how a
|
|
12
|
+
* total is summed, why a duplicate is refused — so the card it explains stays
|
|
13
|
+
* short.
|
|
14
|
+
*
|
|
15
|
+
* Guidance that changes with the value or the state should stay on the page
|
|
16
|
+
* instead: folding it away hides exactly when it matters.
|
|
17
|
+
*
|
|
18
|
+
* Built on `Popover`, so the panel is a labelled dialog on the popover layer
|
|
19
|
+
* and keeps Popover's `popover-content` / `popover-positioner` hooks, as the
|
|
20
|
+
* pickers do. The icon button is `info-popover-trigger`.
|
|
21
|
+
*/
|
|
22
|
+
function InfoPopover({
|
|
23
|
+
children,
|
|
24
|
+
className,
|
|
25
|
+
iconSize = 14,
|
|
26
|
+
label = "More information",
|
|
27
|
+
triggerClassName,
|
|
28
|
+
width = 300,
|
|
29
|
+
side,
|
|
30
|
+
align,
|
|
31
|
+
...rootProps
|
|
32
|
+
}) {
|
|
33
|
+
const style = {
|
|
34
|
+
"--cocso-info-popover-width": typeof width === "number" ? `${width}px` : width
|
|
35
|
+
};
|
|
36
|
+
return /*#__PURE__*/jsxRuntime.jsxs(popover.Popover, {
|
|
37
|
+
...rootProps,
|
|
38
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(popover.Popover.Trigger, {
|
|
39
|
+
"aria-label": label,
|
|
40
|
+
className: cn.cn(infoPopover_module.trigger, triggerClassName),
|
|
41
|
+
"data-cocso-component": "info-popover-trigger",
|
|
42
|
+
children: /*#__PURE__*/jsxRuntime.jsx(reactIcons.InfoIcon, {
|
|
43
|
+
"aria-hidden": "true",
|
|
44
|
+
size: iconSize
|
|
45
|
+
})
|
|
46
|
+
}), /*#__PURE__*/jsxRuntime.jsx(popover.Popover.Content, {
|
|
47
|
+
align: align,
|
|
48
|
+
"aria-label": label,
|
|
49
|
+
className: cn.cn(infoPopover_module.content, className),
|
|
50
|
+
side: side,
|
|
51
|
+
style: style,
|
|
52
|
+
children: children
|
|
53
|
+
})]
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.InfoPopover = InfoPopover;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styleInject_es = require('../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js');
|
|
4
|
+
|
|
5
|
+
var css_248z = "@layer components{.info-popover-module_trigger__-FJSm{align-items:center;background:none;border:none;border-radius:var(--cocso-radius-full);color:var(--cocso-color-text-secondary);cursor:pointer;display:inline-flex;flex-shrink:0;justify-content:center;min-block-size:24px;min-inline-size:24px;padding:0;transition:color var(--cocso-duration-fast) var(--cocso-easing-soft)}.info-popover-module_trigger__-FJSm:hover,.info-popover-module_trigger__-FJSm[data-popup-open]{color:var(--cocso-color-text-primary)}.info-popover-module_trigger__-FJSm:focus-visible{outline:2px solid var(--cocso-color-focus-ring);outline-offset:2px}@media (prefers-reduced-motion:reduce){.info-popover-module_trigger__-FJSm{transition:none}}.info-popover-module_content__A4QVA.info-popover-module_content__A4QVA{color:var(--cocso-color-text-primary);font-weight:var(--cocso-font-weight-medium);inline-size:var(--cocso-info-popover-width);max-inline-size:calc(100vw - var(--cocso-spacing-12));overflow-wrap:anywhere;white-space:normal;word-break:keep-all}}";
|
|
6
|
+
var styles = {"trigger":"info-popover-module_trigger__-FJSm","content":"info-popover-module_content__A4QVA"};
|
|
7
|
+
styleInject_es(css_248z);
|
|
8
|
+
|
|
9
|
+
module.exports = styles;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
|
|
4
|
+
interface LoadingOverlayProps extends Omit<ComponentProps<"div">, "children"> {
|
|
5
|
+
/** Secondary guidance under the message — how long it takes, not to close the window. */
|
|
6
|
+
description?: string;
|
|
7
|
+
/** The main line under the spinner. Also the spinner's accessible name. */
|
|
8
|
+
message?: string;
|
|
9
|
+
/** Renders the overlay only while true; renders nothing otherwise. */
|
|
10
|
+
open: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A layer that covers the whole viewport while a long task runs.
|
|
14
|
+
*
|
|
15
|
+
* For work that takes several seconds and must not be interrupted — an
|
|
16
|
+
* upload, say. It is `position: fixed`, so in a popup window opened with
|
|
17
|
+
* `window.open` it covers that whole window.
|
|
18
|
+
*
|
|
19
|
+
* It blocks the pointer, not the keyboard: content underneath stays in the
|
|
20
|
+
* tab order. Mark it `inert` yourself if the task must not be re-triggered
|
|
21
|
+
* from the keyboard.
|
|
22
|
+
*
|
|
23
|
+
* It sits on `--cocso-z-index-overlay`, the dialog backdrop layer, so it is
|
|
24
|
+
* drawn under an open `Dialog` panel. Override the z-index through
|
|
25
|
+
* `[data-cocso-component="loading-overlay"]` when it has to cover one.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* <LoadingOverlay open={isPending} message="정산 데이터를 업로드하고 있습니다" />
|
|
29
|
+
*/
|
|
30
|
+
declare function LoadingOverlay({ ref, className, open, message, description, ...props }: LoadingOverlayProps): react_jsx_runtime.JSX.Element | null;
|
|
31
|
+
|
|
32
|
+
export { LoadingOverlay };
|
|
33
|
+
export type { LoadingOverlayProps };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var cn = require('../../cn.js');
|
|
5
|
+
var loadingOverlay_module = require('./loading-overlay.module.css.js');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var spinner = require('../spinner/spinner.js');
|
|
8
|
+
var typography = require('../typography/typography.js');
|
|
9
|
+
var color = require('../../token/color.js');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A layer that covers the whole viewport while a long task runs.
|
|
13
|
+
*
|
|
14
|
+
* For work that takes several seconds and must not be interrupted — an
|
|
15
|
+
* upload, say. It is `position: fixed`, so in a popup window opened with
|
|
16
|
+
* `window.open` it covers that whole window.
|
|
17
|
+
*
|
|
18
|
+
* It blocks the pointer, not the keyboard: content underneath stays in the
|
|
19
|
+
* tab order. Mark it `inert` yourself if the task must not be re-triggered
|
|
20
|
+
* from the keyboard.
|
|
21
|
+
*
|
|
22
|
+
* It sits on `--cocso-z-index-overlay`, the dialog backdrop layer, so it is
|
|
23
|
+
* drawn under an open `Dialog` panel. Override the z-index through
|
|
24
|
+
* `[data-cocso-component="loading-overlay"]` when it has to cover one.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* <LoadingOverlay open={isPending} message="정산 데이터를 업로드하고 있습니다" />
|
|
28
|
+
*/
|
|
29
|
+
function LoadingOverlay({
|
|
30
|
+
ref,
|
|
31
|
+
className,
|
|
32
|
+
open,
|
|
33
|
+
message = "처리 중입니다",
|
|
34
|
+
description,
|
|
35
|
+
...props
|
|
36
|
+
}) {
|
|
37
|
+
if (!open) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
41
|
+
"aria-busy": "true",
|
|
42
|
+
className: cn.cn(loadingOverlay_module.overlay, className),
|
|
43
|
+
"data-cocso-component": "loading-overlay",
|
|
44
|
+
ref: ref,
|
|
45
|
+
...props,
|
|
46
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(spinner.Spinner, {
|
|
47
|
+
label: message,
|
|
48
|
+
size: "large",
|
|
49
|
+
variant: "primary"
|
|
50
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
51
|
+
className: loadingOverlay_module.text,
|
|
52
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(typography.Typography, {
|
|
53
|
+
color: color.colors.textPrimary,
|
|
54
|
+
type: "body",
|
|
55
|
+
weight: "medium",
|
|
56
|
+
children: message
|
|
57
|
+
}), description && /*#__PURE__*/jsxRuntime.jsx(typography.Typography, {
|
|
58
|
+
className: loadingOverlay_module.description,
|
|
59
|
+
color: color.colors.textSecondary,
|
|
60
|
+
size: "small",
|
|
61
|
+
type: "body",
|
|
62
|
+
children: description
|
|
63
|
+
})]
|
|
64
|
+
})]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.LoadingOverlay = LoadingOverlay;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styleInject_es = require('../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js');
|
|
4
|
+
|
|
5
|
+
var css_248z = "@layer components{.loading-overlay-module_overlay__Xnl3P{align-items:center;backdrop-filter:blur(2px);background-color:var(--cocso-color-surface-glass);display:flex;flex-direction:column;gap:var(--cocso-spacing-7);inset:0;justify-content:center;padding-inline:var(--cocso-spacing-10);position:fixed;z-index:var(--cocso-z-index-overlay)}.loading-overlay-module_text__1581R{align-items:center;display:flex;flex-direction:column;gap:var(--cocso-spacing-3)}.loading-overlay-module_description__o0pJf{text-align:center}}";
|
|
6
|
+
var styles = {"overlay":"loading-overlay-module_overlay__Xnl3P","text":"loading-overlay-module_text__1581R","description":"loading-overlay-module_description__o0pJf"};
|
|
7
|
+
styleInject_es(css_248z);
|
|
8
|
+
|
|
9
|
+
module.exports = styles;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { InputProps } from '../input/input.js';
|
|
3
|
+
|
|
4
|
+
interface NumberInputProps extends Omit<InputProps, "type" | "value" | "defaultValue" | "onChange" | "passwordToggle"> {
|
|
5
|
+
/** Decimal places a user may type. `0`, the default, is a whole amount. */
|
|
6
|
+
maxFractionDigits?: number;
|
|
7
|
+
/** The parsed number on every edit, or `null` when the field is empty. */
|
|
8
|
+
onValueChange: (value: number | null) => void;
|
|
9
|
+
/** The current number. `null` or `undefined` shows an empty field. */
|
|
10
|
+
value: number | null | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* An `Input` for amounts, grouped in thousands as the user types.
|
|
14
|
+
*
|
|
15
|
+
* It is a text field with `inputMode`, not `type="number"`: a native number
|
|
16
|
+
* input cannot display a separator. The caret is put back after the same digit
|
|
17
|
+
* when a comma is inserted or removed in front of it.
|
|
18
|
+
*
|
|
19
|
+
* Defaults to the `small` size and the full width of its container, the shape
|
|
20
|
+
* the field had where it came from; both can be overridden.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* <Controller
|
|
24
|
+
* control={control}
|
|
25
|
+
* name="amount"
|
|
26
|
+
* render={({ field }) => (
|
|
27
|
+
* <NumberInput
|
|
28
|
+
* aria-label="금액"
|
|
29
|
+
* onBlur={field.onBlur}
|
|
30
|
+
* onValueChange={field.onChange}
|
|
31
|
+
* value={field.value}
|
|
32
|
+
* />
|
|
33
|
+
* )}
|
|
34
|
+
* />
|
|
35
|
+
*/
|
|
36
|
+
declare function NumberInput({ value, onValueChange, maxFractionDigits, onBlur, size, stretch, ...props }: NumberInputProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
export { NumberInput };
|
|
39
|
+
export type { NumberInputProps };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var input = require('../input/input.js');
|
|
7
|
+
|
|
8
|
+
const NON_NUMERIC = /[^0-9.]/g;
|
|
9
|
+
const ALL_POINTS = /\./g;
|
|
10
|
+
const LEADING_ZEROS = /^0+(?=\d)/;
|
|
11
|
+
const THOUSANDS = /\B(?=(\d{3})+(?!\d))/g;
|
|
12
|
+
const GROUP_SEPARATORS = /,/g;
|
|
13
|
+
const NUMERIC_CHAR = /[0-9.]/;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Keeps digits and the decimal point, plus a leading `-`.
|
|
17
|
+
*
|
|
18
|
+
* With `maxFractionDigits` 0 the point is dropped; otherwise only the first
|
|
19
|
+
* point survives and the fraction is cut to length. Leading zeros on the
|
|
20
|
+
* integer part go too, so typing after a prefilled `0` gives `5`, not `05`.
|
|
21
|
+
*/
|
|
22
|
+
function sanitizeNumeric(raw, maxFractionDigits) {
|
|
23
|
+
const sign = raw.trimStart().startsWith("-") ? "-" : "";
|
|
24
|
+
let cleaned = raw.replace(NON_NUMERIC, "");
|
|
25
|
+
if (maxFractionDigits === 0) {
|
|
26
|
+
cleaned = cleaned.replace(ALL_POINTS, "");
|
|
27
|
+
} else {
|
|
28
|
+
const dot = cleaned.indexOf(".");
|
|
29
|
+
if (dot !== -1) {
|
|
30
|
+
const integer = cleaned.slice(0, dot);
|
|
31
|
+
const fraction = cleaned.slice(dot + 1).replace(ALL_POINTS, "").slice(0, maxFractionDigits);
|
|
32
|
+
cleaned = `${integer}.${fraction}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// "0123" becomes "123"; the zero in "0" and "0.5" stays.
|
|
36
|
+
cleaned = cleaned.replace(LEADING_ZEROS, "");
|
|
37
|
+
return `${sign}${cleaned}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Groups the integer part in thousands. The sign and fraction are kept as they are. */
|
|
41
|
+
function formatWithGrouping(numeric) {
|
|
42
|
+
const sign = numeric.startsWith("-") ? "-" : "";
|
|
43
|
+
const [integer = "", fraction] = numeric.slice(sign.length).split(".");
|
|
44
|
+
const grouped = integer.replace(THOUSANDS, ",");
|
|
45
|
+
return fraction === undefined ? `${sign}${grouped}` : `${sign}${grouped}.${fraction}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Display text to a number; `null` when it is empty or not yet a number. */
|
|
49
|
+
function parseNumeric(display) {
|
|
50
|
+
const numeric = display.replace(GROUP_SEPARATORS, "");
|
|
51
|
+
if (numeric === "" || numeric === "." || numeric === "-") {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const parsed = Number(numeric);
|
|
55
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
56
|
+
}
|
|
57
|
+
function toDisplay(value) {
|
|
58
|
+
return value == null ? "" : formatWithGrouping(String(value));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* An `Input` for amounts, grouped in thousands as the user types.
|
|
62
|
+
*
|
|
63
|
+
* It is a text field with `inputMode`, not `type="number"`: a native number
|
|
64
|
+
* input cannot display a separator. The caret is put back after the same digit
|
|
65
|
+
* when a comma is inserted or removed in front of it.
|
|
66
|
+
*
|
|
67
|
+
* Defaults to the `small` size and the full width of its container, the shape
|
|
68
|
+
* the field had where it came from; both can be overridden.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* <Controller
|
|
72
|
+
* control={control}
|
|
73
|
+
* name="amount"
|
|
74
|
+
* render={({ field }) => (
|
|
75
|
+
* <NumberInput
|
|
76
|
+
* aria-label="금액"
|
|
77
|
+
* onBlur={field.onBlur}
|
|
78
|
+
* onValueChange={field.onChange}
|
|
79
|
+
* value={field.value}
|
|
80
|
+
* />
|
|
81
|
+
* )}
|
|
82
|
+
* />
|
|
83
|
+
*/
|
|
84
|
+
function NumberInput({
|
|
85
|
+
value,
|
|
86
|
+
onValueChange,
|
|
87
|
+
maxFractionDigits = 0,
|
|
88
|
+
onBlur,
|
|
89
|
+
size = "small",
|
|
90
|
+
stretch = true,
|
|
91
|
+
...props
|
|
92
|
+
}) {
|
|
93
|
+
// An external value is formatted as given; the fraction limit applies to
|
|
94
|
+
// what is typed, not to what the caller supplies.
|
|
95
|
+
const [draft, setDraft] = react.useState(() => toDisplay(value));
|
|
96
|
+
// What this field last reported, to tell its own edits from a caller's reset.
|
|
97
|
+
const lastEmitted = react.useRef(value ?? null);
|
|
98
|
+
const frame = react.useRef(null);
|
|
99
|
+
|
|
100
|
+
// Only a value that did not come from this field rewrites the text, so an
|
|
101
|
+
// intermediate state like "1." survives the re-render its own edit causes.
|
|
102
|
+
react.useEffect(() => {
|
|
103
|
+
const next = value ?? null;
|
|
104
|
+
if (next === lastEmitted.current) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
lastEmitted.current = next;
|
|
108
|
+
setDraft(toDisplay(next));
|
|
109
|
+
}, [value]);
|
|
110
|
+
react.useEffect(() => () => {
|
|
111
|
+
if (frame.current !== null) {
|
|
112
|
+
cancelAnimationFrame(frame.current);
|
|
113
|
+
}
|
|
114
|
+
}, []);
|
|
115
|
+
const handleChange = event => {
|
|
116
|
+
const el = event.currentTarget;
|
|
117
|
+
const caret = el.selectionStart ?? el.value.length;
|
|
118
|
+
// Count the digits before the caret, then put it back after the same digit
|
|
119
|
+
// once the commas have moved.
|
|
120
|
+
const digitsBeforeCaret = el.value.slice(0, caret).replace(NON_NUMERIC, "").length;
|
|
121
|
+
const numeric = sanitizeNumeric(el.value, maxFractionDigits);
|
|
122
|
+
const formatted = formatWithGrouping(numeric);
|
|
123
|
+
setDraft(formatted);
|
|
124
|
+
const parsed = parseNumeric(numeric);
|
|
125
|
+
lastEmitted.current = parsed;
|
|
126
|
+
onValueChange(parsed);
|
|
127
|
+
if (frame.current !== null) {
|
|
128
|
+
cancelAnimationFrame(frame.current);
|
|
129
|
+
}
|
|
130
|
+
frame.current = requestAnimationFrame(() => {
|
|
131
|
+
frame.current = null;
|
|
132
|
+
let position = formatted.startsWith("-") ? 1 : 0;
|
|
133
|
+
let count = 0;
|
|
134
|
+
while (position < formatted.length && count < digitsBeforeCaret) {
|
|
135
|
+
if (NUMERIC_CHAR.test(formatted.charAt(position))) {
|
|
136
|
+
count += 1;
|
|
137
|
+
}
|
|
138
|
+
position += 1;
|
|
139
|
+
}
|
|
140
|
+
if (document.activeElement === el) {
|
|
141
|
+
el.setSelectionRange(position, position);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
const handleBlur = event => {
|
|
146
|
+
// Tidy what typing leaves behind: a trailing point, a lone sign.
|
|
147
|
+
setDraft(previous => {
|
|
148
|
+
const trimmed = previous.endsWith(".") ? previous.slice(0, -1) : previous;
|
|
149
|
+
return trimmed === "-" ? "" : trimmed;
|
|
150
|
+
});
|
|
151
|
+
onBlur?.(event);
|
|
152
|
+
};
|
|
153
|
+
return /*#__PURE__*/jsxRuntime.jsx(input.Input, {
|
|
154
|
+
autoComplete: "off",
|
|
155
|
+
"data-cocso-component": "number-input",
|
|
156
|
+
inputMode: maxFractionDigits > 0 ? "decimal" : "numeric",
|
|
157
|
+
size: size,
|
|
158
|
+
stretch: stretch,
|
|
159
|
+
...props,
|
|
160
|
+
onBlur: handleBlur,
|
|
161
|
+
onChange: handleChange,
|
|
162
|
+
type: "text",
|
|
163
|
+
value: draft
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
exports.NumberInput = NumberInput;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ComponentProps, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type SectionHeaderLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
5
|
+
interface SectionHeaderProps extends Omit<ComponentProps<"div">, "title"> {
|
|
6
|
+
/**
|
|
7
|
+
* Trailing controls — buttons, a menu, a search box. When the header is too
|
|
8
|
+
* narrow to keep `MIN_TITLE_WIDTH` for the title they collapse behind one
|
|
9
|
+
* toggle button.
|
|
10
|
+
*/
|
|
11
|
+
actions?: ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Collapses `actions` behind a toggle when they would crowd the title.
|
|
14
|
+
* Defaults to `true`.
|
|
15
|
+
*/
|
|
16
|
+
collapsible?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Opens the collapsed panel on mount. Only meaningful while collapsed; mostly
|
|
19
|
+
* for showing the panel in documentation.
|
|
20
|
+
*/
|
|
21
|
+
defaultActionsOpen?: boolean;
|
|
22
|
+
/** Secondary text under the title. */
|
|
23
|
+
description?: ReactNode;
|
|
24
|
+
/** Heading level of the title. Defaults to `2`. */
|
|
25
|
+
level?: SectionHeaderLevel;
|
|
26
|
+
/** Text of the toggle the actions collapse into. Defaults to `"More"`. */
|
|
27
|
+
moreLabel?: string;
|
|
28
|
+
title: ReactNode;
|
|
29
|
+
/** Class for the title element, e.g. to truncate a long title. */
|
|
30
|
+
titleClassName?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The heading row of a section or a card: a title, its actions on the same
|
|
34
|
+
* line, and an optional description under them.
|
|
35
|
+
*
|
|
36
|
+
* When the row gets too narrow for the actions to sit beside the title, they
|
|
37
|
+
* collapse behind a single toggle and open in a panel under it, so the title
|
|
38
|
+
* is never squeezed to nothing.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* <Card>
|
|
42
|
+
* <SectionHeader actions={<Button>Add</Button>} title="Medicines" />
|
|
43
|
+
* </Card>
|
|
44
|
+
*/
|
|
45
|
+
declare function SectionHeader({ className, title, titleClassName, description, actions, level, moreLabel, collapsible, defaultActionsOpen, ...props }: SectionHeaderProps): react_jsx_runtime.JSX.Element;
|
|
46
|
+
|
|
47
|
+
export { SectionHeader };
|
|
48
|
+
export type { SectionHeaderLevel, SectionHeaderProps };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var reactIcons = require('@cocso-ui/react-icons');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var cn = require('../../cn.js');
|
|
7
|
+
var sectionHeader_module = require('./section-header.module.css.js');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
var typography = require('../typography/typography.js');
|
|
10
|
+
var button = require('../button/button.js');
|
|
11
|
+
|
|
12
|
+
const MIN_TITLE_WIDTH = 120;
|
|
13
|
+
/** The gap between the title and the actions — `--cocso-spacing-5`. */
|
|
14
|
+
const HEADER_GAP = 8;
|
|
15
|
+
/** The least room left between the open panel and the viewport edge. */
|
|
16
|
+
const PANEL_MARGIN = 16;
|
|
17
|
+
/** The gap between the toggle and the panel under it. */
|
|
18
|
+
const PANEL_OFFSET = 4;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Floating layers an action may have opened from inside the panel — a menu, a
|
|
22
|
+
* dialog. Interacting with one does not close the panel, and Escape belongs
|
|
23
|
+
* to it first.
|
|
24
|
+
*/
|
|
25
|
+
const FLOATING_SELECTOR = '[role="menu"],[role="dialog"],[role="alertdialog"],[role="listbox"]';
|
|
26
|
+
function measurePanel(toggle) {
|
|
27
|
+
const rect = toggle.getBoundingClientRect();
|
|
28
|
+
const viewport = document.documentElement.clientWidth;
|
|
29
|
+
const rtl = getComputedStyle(toggle).direction === "rtl";
|
|
30
|
+
return {
|
|
31
|
+
top: rect.bottom + PANEL_OFFSET,
|
|
32
|
+
insetInlineEnd: rtl ? rect.left : viewport - rect.right,
|
|
33
|
+
maxWidth: (rtl ? viewport - rect.left : rect.right) - PANEL_MARGIN
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The actions slot. When it runs out of room it hands its content to a panel
|
|
39
|
+
* that opens under a toggle.
|
|
40
|
+
*
|
|
41
|
+
* The actions are hidden, never unmounted, while the panel is closed, and the
|
|
42
|
+
* panel is the same element as the inline slot. An action that owns a dialog
|
|
43
|
+
* keeps its state through a collapse, and a dialog opened from the panel
|
|
44
|
+
* survives the panel closing. That is also why this is not built on
|
|
45
|
+
* `Popover`: a portal moves the actions to another tree and remounts them.
|
|
46
|
+
* The panel is a disclosure — the toggle carries `aria-expanded` and
|
|
47
|
+
* `aria-controls` — not a dialog.
|
|
48
|
+
*/
|
|
49
|
+
function CollapsibleActions({
|
|
50
|
+
actions,
|
|
51
|
+
collapsible,
|
|
52
|
+
defaultOpen,
|
|
53
|
+
moreLabel
|
|
54
|
+
}) {
|
|
55
|
+
const panelId = react.useId();
|
|
56
|
+
const actionsRef = react.useRef(null);
|
|
57
|
+
const toggleRef = react.useRef(null);
|
|
58
|
+
const [collapsed, setCollapsed] = react.useState(false);
|
|
59
|
+
const [open, setOpen] = react.useState(defaultOpen);
|
|
60
|
+
const [position, setPosition] = react.useState(null);
|
|
61
|
+
|
|
62
|
+
// Once collapsed the slot no longer has an inline width to measure, so the
|
|
63
|
+
// width it had while expanded is kept.
|
|
64
|
+
const expandedWidthRef = react.useRef(0);
|
|
65
|
+
const collapsedRef = react.useRef(false);
|
|
66
|
+
react.useLayoutEffect(() => {
|
|
67
|
+
const element = actionsRef.current;
|
|
68
|
+
const header = element?.parentElement;
|
|
69
|
+
if (!(collapsible && header && element)) {
|
|
70
|
+
collapsedRef.current = false;
|
|
71
|
+
setCollapsed(false);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const measure = () => {
|
|
75
|
+
if (!collapsedRef.current) {
|
|
76
|
+
expandedWidthRef.current = element.offsetWidth;
|
|
77
|
+
}
|
|
78
|
+
const next = header.clientWidth < expandedWidthRef.current + HEADER_GAP + MIN_TITLE_WIDTH;
|
|
79
|
+
collapsedRef.current = next;
|
|
80
|
+
setCollapsed(next);
|
|
81
|
+
// Widening closes the panel, so narrowing again later does not bring
|
|
82
|
+
// it back by itself.
|
|
83
|
+
if (!next) {
|
|
84
|
+
setOpen(false);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
measure();
|
|
88
|
+
const observer = new ResizeObserver(measure);
|
|
89
|
+
observer.observe(header);
|
|
90
|
+
observer.observe(element);
|
|
91
|
+
return () => observer.disconnect();
|
|
92
|
+
}, [collapsible]);
|
|
93
|
+
const expanded = collapsed && open;
|
|
94
|
+
react.useLayoutEffect(() => {
|
|
95
|
+
if (expanded && toggleRef.current) {
|
|
96
|
+
setPosition(measurePanel(toggleRef.current));
|
|
97
|
+
} else {
|
|
98
|
+
setPosition(null);
|
|
99
|
+
}
|
|
100
|
+
}, [expanded]);
|
|
101
|
+
react.useEffect(() => {
|
|
102
|
+
if (!expanded) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const isInside = target => target instanceof Element && (Boolean(actionsRef.current?.contains(target)) || Boolean(toggleRef.current?.contains(target)) || Boolean(target.closest(FLOATING_SELECTOR)));
|
|
106
|
+
const close = event => {
|
|
107
|
+
if (!isInside(event.target)) {
|
|
108
|
+
setOpen(false);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const closeOnEscape = event => {
|
|
112
|
+
if (event.key === "Escape" && !document.querySelector(FLOATING_SELECTOR)) {
|
|
113
|
+
setOpen(false);
|
|
114
|
+
toggleRef.current?.focus();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
document.addEventListener("click", close);
|
|
118
|
+
document.addEventListener("keydown", closeOnEscape);
|
|
119
|
+
window.addEventListener("scroll", close, true);
|
|
120
|
+
return () => {
|
|
121
|
+
document.removeEventListener("click", close);
|
|
122
|
+
document.removeEventListener("keydown", closeOnEscape);
|
|
123
|
+
window.removeEventListener("scroll", close, true);
|
|
124
|
+
};
|
|
125
|
+
}, [expanded]);
|
|
126
|
+
const style = expanded && position ? position : undefined;
|
|
127
|
+
let state;
|
|
128
|
+
if (collapsed) {
|
|
129
|
+
state = open ? "open" : "closed";
|
|
130
|
+
}
|
|
131
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
132
|
+
children: [collapsed && /*#__PURE__*/jsxRuntime.jsx(button.Button, {
|
|
133
|
+
"aria-controls": panelId,
|
|
134
|
+
"aria-expanded": open,
|
|
135
|
+
className: sectionHeader_module.toggle,
|
|
136
|
+
onClick: () => setOpen(current => !current),
|
|
137
|
+
ref: toggleRef,
|
|
138
|
+
size: "x-small",
|
|
139
|
+
suffix: /*#__PURE__*/jsxRuntime.jsx(reactIcons.ChevronDownIcon, {
|
|
140
|
+
size: 14
|
|
141
|
+
}),
|
|
142
|
+
type: "button",
|
|
143
|
+
variant: "outline",
|
|
144
|
+
children: moreLabel
|
|
145
|
+
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
146
|
+
className: cn.cn(sectionHeader_module.actions, collapsed && sectionHeader_module.panel),
|
|
147
|
+
"data-cocso-component": "section-header-actions",
|
|
148
|
+
"data-state": state,
|
|
149
|
+
hidden: collapsed && !open,
|
|
150
|
+
id: panelId,
|
|
151
|
+
ref: actionsRef,
|
|
152
|
+
style: style,
|
|
153
|
+
children: actions
|
|
154
|
+
})]
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The heading row of a section or a card: a title, its actions on the same
|
|
160
|
+
* line, and an optional description under them.
|
|
161
|
+
*
|
|
162
|
+
* When the row gets too narrow for the actions to sit beside the title, they
|
|
163
|
+
* collapse behind a single toggle and open in a panel under it, so the title
|
|
164
|
+
* is never squeezed to nothing.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* <Card>
|
|
168
|
+
* <SectionHeader actions={<Button>Add</Button>} title="Medicines" />
|
|
169
|
+
* </Card>
|
|
170
|
+
*/
|
|
171
|
+
function SectionHeader({
|
|
172
|
+
className,
|
|
173
|
+
title,
|
|
174
|
+
titleClassName,
|
|
175
|
+
description,
|
|
176
|
+
actions,
|
|
177
|
+
level = 2,
|
|
178
|
+
moreLabel = "More",
|
|
179
|
+
collapsible = true,
|
|
180
|
+
defaultActionsOpen = false,
|
|
181
|
+
...props
|
|
182
|
+
}) {
|
|
183
|
+
const Heading = `h${level}`;
|
|
184
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
185
|
+
className: cn.cn(sectionHeader_module.root, className),
|
|
186
|
+
"data-cocso-component": "section-header",
|
|
187
|
+
...props,
|
|
188
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
189
|
+
className: sectionHeader_module.row,
|
|
190
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(typography.Typography, {
|
|
191
|
+
className: cn.cn(sectionHeader_module.title, titleClassName),
|
|
192
|
+
render: /*#__PURE__*/jsxRuntime.jsx(Heading, {}),
|
|
193
|
+
size: "small",
|
|
194
|
+
type: "heading",
|
|
195
|
+
weight: "bold",
|
|
196
|
+
children: title
|
|
197
|
+
}), actions ? /*#__PURE__*/jsxRuntime.jsx(CollapsibleActions, {
|
|
198
|
+
actions: actions,
|
|
199
|
+
collapsible: collapsible,
|
|
200
|
+
defaultOpen: defaultActionsOpen,
|
|
201
|
+
moreLabel: moreLabel
|
|
202
|
+
}) : null]
|
|
203
|
+
}), description ? /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
204
|
+
className: sectionHeader_module.description,
|
|
205
|
+
children: description
|
|
206
|
+
}) : null]
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
exports.SectionHeader = SectionHeader;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styleInject_es = require('../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js');
|
|
4
|
+
|
|
5
|
+
var css_248z = "@layer components{.section-header-module_root__sOgb3{display:flex;flex-direction:column;gap:var(--cocso-spacing-3);min-inline-size:0}.section-header-module_row__xsVIe{align-items:center;display:flex;gap:var(--cocso-spacing-5);justify-content:space-between;min-block-size:var(--cocso-spacing-12)}.section-header-module_title__7ddbh{color:var(--cocso-color-text-primary);flex:1;margin:0;min-inline-size:0;word-break:keep-all}.section-header-module_description__T8tck{color:var(--cocso-color-text-secondary);font-size:var(--cocso-text-xs);margin:0}.section-header-module_toggle__bVZ9N{flex-shrink:0}.section-header-module_actions__kS-uK{align-items:center;display:flex;flex-shrink:0;gap:var(--cocso-spacing-5)}.section-header-module_actions__kS-uK[hidden]{display:none}.section-header-module_panel__1Zc9C{background-color:var(--cocso-color-surface-primary);border:1px solid var(--cocso-color-border-secondary);border-radius:var(--cocso-radius-4);box-shadow:var(--cocso-shadow-popover);flex-wrap:wrap;justify-content:flex-end;padding:var(--cocso-spacing-5);position:fixed;z-index:var(--cocso-z-index-popover)}.section-header-module_panel__1Zc9C>*{flex-shrink:1;flex-wrap:wrap;justify-content:flex-end;max-inline-size:100%;white-space:normal}}";
|
|
6
|
+
var styles = {"root":"section-header-module_root__sOgb3","row":"section-header-module_row__xsVIe","title":"section-header-module_title__7ddbh","description":"section-header-module_description__T8tck","toggle":"section-header-module_toggle__bVZ9N","actions":"section-header-module_actions__kS-uK","panel":"section-header-module_panel__1Zc9C"};
|
|
7
|
+
styleInject_es(css_248z);
|
|
8
|
+
|
|
9
|
+
module.exports = styles;
|