@cocso-ui/react 1.10.1 → 1.12.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/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/date-time-picker/date-time-picker.js +99 -76
- package/dist/cjs/components/day-picker/day-picker.js +24 -137
- package/dist/cjs/components/day-picker/day-picker.module.css.js +2 -2
- 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/picker/year-month-view.js +216 -0
- package/dist/cjs/components/picker/year-month-view.module.css.js +9 -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/date-time-picker/date-time-picker.mjs +99 -76
- package/dist/esm/components/day-picker/day-picker.mjs +27 -140
- package/dist/esm/components/day-picker/day-picker.module.css.mjs +1 -1
- 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/picker/year-month-view.mjs +212 -0
- package/dist/esm/components/picker/year-month-view.module.css.mjs +3 -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
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ComponentProps, ReactNode } from 'react';
|
|
3
|
+
import { RenderProp } from '../../primitives/use-render.mjs';
|
|
3
4
|
|
|
4
5
|
/** Inline type aliases — codegen is a devDependency and must not leak into published .d.ts */
|
|
5
6
|
type BreadcrumbSize = "sm" | "md" | "lg";
|
|
7
|
+
/** One step of the path. The last step is the current page and never links. */
|
|
8
|
+
interface BreadcrumbItem {
|
|
9
|
+
/** Where the step leads. A step without one renders as text. */
|
|
10
|
+
href?: string;
|
|
11
|
+
label: ReactNode;
|
|
12
|
+
}
|
|
6
13
|
interface BreadcrumbProps extends ComponentProps<"nav"> {
|
|
14
|
+
/**
|
|
15
|
+
* The path from the root to the current page. When given, it is rendered
|
|
16
|
+
* instead of `children`.
|
|
17
|
+
*/
|
|
18
|
+
items?: readonly BreadcrumbItem[];
|
|
19
|
+
/**
|
|
20
|
+
* Element each linked step renders as — the router's link, for example
|
|
21
|
+
* `renderLink={(props) => <NextLink {...props} href={props.href ?? ""} />}`.
|
|
22
|
+
* It receives `href`, `className` and `children`. Defaults to `<a>`.
|
|
23
|
+
*/
|
|
24
|
+
renderLink?: RenderProp;
|
|
7
25
|
separator?: ReactNode;
|
|
8
26
|
size?: BreadcrumbSize;
|
|
9
27
|
}
|
|
10
|
-
/**
|
|
11
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Navigation hierarchy indicator with configurable separator. Pass the path as
|
|
30
|
+
* `items`, or compose the steps yourself as `children`.
|
|
31
|
+
*/
|
|
32
|
+
declare function Breadcrumb({ ref, className, style, size, separator, items: itemsProp, renderLink, children, ...props }: BreadcrumbProps): react_jsx_runtime.JSX.Element;
|
|
12
33
|
|
|
13
34
|
export { Breadcrumb };
|
|
14
|
-
export type { BreadcrumbProps, BreadcrumbSize };
|
|
35
|
+
export type { BreadcrumbItem, BreadcrumbProps, BreadcrumbSize };
|
|
@@ -4,8 +4,48 @@ import { Children } from 'react';
|
|
|
4
4
|
import { cn } from '../../cn.mjs';
|
|
5
5
|
import styles from './breadcrumb.module.css.mjs';
|
|
6
6
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
7
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
8
|
+
import { mergeProps } from '@base-ui/react/merge-props';
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
function BreadcrumbLink({
|
|
11
|
+
href,
|
|
12
|
+
render,
|
|
13
|
+
children
|
|
14
|
+
}) {
|
|
15
|
+
return useRender({
|
|
16
|
+
render,
|
|
17
|
+
props: mergeProps({
|
|
18
|
+
className: styles.link,
|
|
19
|
+
href
|
|
20
|
+
}, {
|
|
21
|
+
children
|
|
22
|
+
}),
|
|
23
|
+
defaultTagName: "a"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function renderStep(item, isCurrent, renderLink) {
|
|
27
|
+
if (isCurrent) {
|
|
28
|
+
return /*#__PURE__*/jsx("span", {
|
|
29
|
+
"aria-current": "page",
|
|
30
|
+
children: item.label
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (item.href === undefined) {
|
|
34
|
+
return /*#__PURE__*/jsx("span", {
|
|
35
|
+
children: item.label
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return /*#__PURE__*/jsx(BreadcrumbLink, {
|
|
39
|
+
href: item.href,
|
|
40
|
+
render: renderLink,
|
|
41
|
+
children: item.label
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Navigation hierarchy indicator with configurable separator. Pass the path as
|
|
47
|
+
* `items`, or compose the steps yourself as `children`.
|
|
48
|
+
*/
|
|
9
49
|
function Breadcrumb({
|
|
10
50
|
ref,
|
|
11
51
|
className,
|
|
@@ -15,10 +55,12 @@ function Breadcrumb({
|
|
|
15
55
|
height: "1em",
|
|
16
56
|
width: "1em"
|
|
17
57
|
}),
|
|
58
|
+
items: itemsProp,
|
|
59
|
+
renderLink,
|
|
18
60
|
children,
|
|
19
61
|
...props
|
|
20
62
|
}) {
|
|
21
|
-
const items = Children.toArray(children);
|
|
63
|
+
const items = itemsProp === undefined ? Children.toArray(children) : itemsProp.map((item, index) => renderStep(item, index === itemsProp.length - 1, renderLink));
|
|
22
64
|
return /*#__PURE__*/jsx("nav", {
|
|
23
65
|
"aria-label": "Breadcrumb",
|
|
24
66
|
className: cn(breadcrumb({
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var styles = {"breadcrumb":"breadcrumb-module_breadcrumb__dW5v-","list":"breadcrumb-module_list__mLCBo","item":"breadcrumb-module_item__G0t2y","separator":"breadcrumb-module_separator__wMAks"};
|
|
1
|
+
var styles = {"breadcrumb":"breadcrumb-module_breadcrumb__dW5v-","list":"breadcrumb-module_list__mLCBo","item":"breadcrumb-module_item__G0t2y","separator":"breadcrumb-module_separator__wMAks","link":"breadcrumb-module_link__cclmN"};
|
|
2
2
|
|
|
3
3
|
export { styles as default };
|
|
@@ -1,13 +1,60 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
2
3
|
import { ComponentProps } from 'react';
|
|
4
|
+
import { RenderProp } from '../../primitives/use-render.mjs';
|
|
5
|
+
import { TypographyProps } from '../typography/typography.mjs';
|
|
3
6
|
|
|
4
7
|
type CardVariant = "elevated" | "outlined" | "filled" | "glass";
|
|
5
8
|
type CardPadding = "sm" | "md" | "lg";
|
|
6
9
|
interface CardProps extends ComponentProps<"div"> {
|
|
10
|
+
/**
|
|
11
|
+
* Space between the card's children. A number is read as pixels; a string is
|
|
12
|
+
* used as-is. Unset, the children sit flush, as before this prop existed.
|
|
13
|
+
*/
|
|
14
|
+
gap?: number | string;
|
|
7
15
|
padding?: CardPadding;
|
|
16
|
+
/**
|
|
17
|
+
* Render the card as another element — `render={<button type="button" />}`
|
|
18
|
+
* or `render={(props) => <NextLink href="…" {...props} />}`. The card's
|
|
19
|
+
* class names, style and children are merged onto it.
|
|
20
|
+
*/
|
|
21
|
+
render?: RenderProp;
|
|
8
22
|
variant?: CardVariant;
|
|
9
23
|
}
|
|
10
|
-
declare function
|
|
24
|
+
declare function CardRoot({ ref, render: renderProp, className, style: _style, variant, padding, gap, children, ...props }: CardProps): react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
25
|
+
type CardHeaderProps = ComponentProps<"div">;
|
|
26
|
+
/**
|
|
27
|
+
* The card's top row: a title on the inline-start side, actions on the end.
|
|
28
|
+
* It keeps one height whether or not an action is there, so the content below
|
|
29
|
+
* does not shift when a button comes and goes.
|
|
30
|
+
*/
|
|
31
|
+
declare function CardHeader({ className, ...props }: CardHeaderProps): react_jsx_runtime.JSX.Element;
|
|
32
|
+
type HeadingTypographyProps = Extract<TypographyProps, {
|
|
33
|
+
type: "heading";
|
|
34
|
+
}>;
|
|
35
|
+
type CardTitleProps = Omit<HeadingTypographyProps, "type">;
|
|
36
|
+
/**
|
|
37
|
+
* The card's heading. An `h2` at the `small` heading step by default; pass
|
|
38
|
+
* `level` for a different rank, or `render` for another element.
|
|
39
|
+
*/
|
|
40
|
+
declare function CardTitle({ className, size, weight, ...props }: CardTitleProps): react_jsx_runtime.JSX.Element;
|
|
41
|
+
/**
|
|
42
|
+
* Surface container. Compose with `Card.Header` and `Card.Title`.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* <Card gap={16} variant="outlined">
|
|
46
|
+
* <Card.Header>
|
|
47
|
+
* <Card.Title>Monthly revenue</Card.Title>
|
|
48
|
+
* <Button size="small">Export</Button>
|
|
49
|
+
* </Card.Header>
|
|
50
|
+
* …
|
|
51
|
+
* </Card>
|
|
52
|
+
*/
|
|
53
|
+
declare const Card: typeof CardRoot & {
|
|
54
|
+
displayName: "Card";
|
|
55
|
+
Header: typeof CardHeader;
|
|
56
|
+
Title: typeof CardTitle;
|
|
57
|
+
};
|
|
11
58
|
|
|
12
59
|
export { Card };
|
|
13
|
-
export type { CardPadding, CardProps, CardVariant };
|
|
60
|
+
export type { CardHeaderProps, CardPadding, CardProps, CardTitleProps, CardVariant };
|
|
@@ -2,26 +2,92 @@ import { card } from '../../ecosystem/codegen/generated/card.mjs';
|
|
|
2
2
|
import { cn } from '../../cn.mjs';
|
|
3
3
|
import styles from './card.module.css.mjs';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { Typography } from '../typography/typography.mjs';
|
|
6
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
7
|
+
import { mergeProps } from '@base-ui/react/merge-props';
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
const toLength = value => typeof value === "number" ? `${value}px` : value;
|
|
10
|
+
function CardRoot({
|
|
7
11
|
ref,
|
|
12
|
+
render: renderProp,
|
|
8
13
|
className,
|
|
9
|
-
style,
|
|
14
|
+
style: _style,
|
|
10
15
|
variant = "elevated",
|
|
11
16
|
padding = "md",
|
|
17
|
+
gap,
|
|
12
18
|
children,
|
|
13
19
|
...props
|
|
20
|
+
}) {
|
|
21
|
+
const style = {
|
|
22
|
+
...(gap === undefined ? {} : {
|
|
23
|
+
"--cocso-card-gap": toLength(gap)
|
|
24
|
+
}),
|
|
25
|
+
..._style
|
|
26
|
+
};
|
|
27
|
+
return useRender({
|
|
28
|
+
render: renderProp,
|
|
29
|
+
ref,
|
|
30
|
+
props: mergeProps({
|
|
31
|
+
className: cn(card({
|
|
32
|
+
variant,
|
|
33
|
+
padding
|
|
34
|
+
}), styles.card, variant === "elevated" && styles.elevated, variant === "glass" && styles.glass, className),
|
|
35
|
+
style
|
|
36
|
+
}, props, {
|
|
37
|
+
children
|
|
38
|
+
}),
|
|
39
|
+
defaultTagName: "div"
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The card's top row: a title on the inline-start side, actions on the end.
|
|
44
|
+
* It keeps one height whether or not an action is there, so the content below
|
|
45
|
+
* does not shift when a button comes and goes.
|
|
46
|
+
*/
|
|
47
|
+
function CardHeader({
|
|
48
|
+
className,
|
|
49
|
+
...props
|
|
14
50
|
}) {
|
|
15
51
|
return /*#__PURE__*/jsx("div", {
|
|
16
|
-
className: cn(
|
|
17
|
-
|
|
18
|
-
padding
|
|
19
|
-
}), styles.card, variant === "elevated" && styles.elevated, variant === "glass" && styles.glass, className),
|
|
20
|
-
ref: ref,
|
|
21
|
-
style: style,
|
|
22
|
-
...props,
|
|
23
|
-
children: children
|
|
52
|
+
className: cn(styles.header, className),
|
|
53
|
+
...props
|
|
24
54
|
});
|
|
25
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The card's heading. An `h2` at the `small` heading step by default; pass
|
|
58
|
+
* `level` for a different rank, or `render` for another element.
|
|
59
|
+
*/
|
|
60
|
+
function CardTitle({
|
|
61
|
+
className,
|
|
62
|
+
size = "small",
|
|
63
|
+
weight = "bold",
|
|
64
|
+
...props
|
|
65
|
+
}) {
|
|
66
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
67
|
+
className: cn(styles.title, className),
|
|
68
|
+
size: size,
|
|
69
|
+
type: "heading",
|
|
70
|
+
weight: weight,
|
|
71
|
+
...props
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Surface container. Compose with `Card.Header` and `Card.Title`.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* <Card gap={16} variant="outlined">
|
|
80
|
+
* <Card.Header>
|
|
81
|
+
* <Card.Title>Monthly revenue</Card.Title>
|
|
82
|
+
* <Button size="small">Export</Button>
|
|
83
|
+
* </Card.Header>
|
|
84
|
+
* …
|
|
85
|
+
* </Card>
|
|
86
|
+
*/
|
|
87
|
+
const Card = Object.assign(CardRoot, {
|
|
88
|
+
displayName: "Card",
|
|
89
|
+
Header: CardHeader,
|
|
90
|
+
Title: CardTitle
|
|
91
|
+
});
|
|
26
92
|
|
|
27
93
|
export { Card };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var styles = {"card":"card-module_card__ZPFTz","elevated":"card-module_elevated__Gua8s","glass":"card-module_glass__u-Nbb"};
|
|
1
|
+
var styles = {"card":"card-module_card__ZPFTz","elevated":"card-module_elevated__Gua8s","glass":"card-module_glass__u-Nbb","header":"card-module_header__tz-Qf","title":"card-module_title__GAX2O"};
|
|
2
2
|
|
|
3
3
|
export { styles as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ButtonProps } from '../button/button.mjs';
|
|
3
|
+
|
|
4
|
+
interface CopyButtonProps extends Omit<ButtonProps, "children" | "svgOnly"> {
|
|
5
|
+
/** Accessible name once the copy succeeded. Defaults to "복사됨". */
|
|
6
|
+
copiedLabel?: string;
|
|
7
|
+
/** Accessible name and tooltip of the button. Defaults to "복사". */
|
|
8
|
+
label?: string;
|
|
9
|
+
/** Called with the error when the copy fails — permission denied, insecure context. */
|
|
10
|
+
onCopyError?: (error: unknown) => void;
|
|
11
|
+
/** Called with the copied text after a successful copy. */
|
|
12
|
+
onCopySuccess?: (text: string) => void;
|
|
13
|
+
/** How long the check mark stays after a successful copy, in seconds. Defaults to 2. */
|
|
14
|
+
resetTimeoutSeconds?: number;
|
|
15
|
+
/** The text written to the clipboard. */
|
|
16
|
+
text: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* An icon button that copies `text` to the clipboard and shows a check mark
|
|
20
|
+
* for a moment.
|
|
21
|
+
*
|
|
22
|
+
* It uses `navigator.clipboard.writeText`, which only works in a secure
|
|
23
|
+
* context (HTTPS or localhost). A failure is reported through `onCopyError`
|
|
24
|
+
* and nowhere else — the library does not log.
|
|
25
|
+
*/
|
|
26
|
+
declare function CopyButton({ text, resetTimeoutSeconds, onCopySuccess, onCopyError, label, copiedLabel, onClick, size, variant, ...props }: CopyButtonProps): react_jsx_runtime.JSX.Element;
|
|
27
|
+
|
|
28
|
+
export { CopyButton };
|
|
29
|
+
export type { CopyButtonProps };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { CheckIcon, ContentCopyIcon } from '@cocso-ui/react-icons';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { Button } from '../button/button.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An icon button that copies `text` to the clipboard and shows a check mark
|
|
9
|
+
* for a moment.
|
|
10
|
+
*
|
|
11
|
+
* It uses `navigator.clipboard.writeText`, which only works in a secure
|
|
12
|
+
* context (HTTPS or localhost). A failure is reported through `onCopyError`
|
|
13
|
+
* and nowhere else — the library does not log.
|
|
14
|
+
*/
|
|
15
|
+
function CopyButton({
|
|
16
|
+
text,
|
|
17
|
+
resetTimeoutSeconds = 2,
|
|
18
|
+
onCopySuccess,
|
|
19
|
+
onCopyError,
|
|
20
|
+
label = "복사",
|
|
21
|
+
copiedLabel = "복사됨",
|
|
22
|
+
onClick,
|
|
23
|
+
size = "x-small",
|
|
24
|
+
variant = "ghost",
|
|
25
|
+
...props
|
|
26
|
+
}) {
|
|
27
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!isCopied) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const timer = setTimeout(() => {
|
|
33
|
+
setIsCopied(false);
|
|
34
|
+
}, resetTimeoutSeconds * 1000);
|
|
35
|
+
return () => clearTimeout(timer);
|
|
36
|
+
}, [isCopied, resetTimeoutSeconds]);
|
|
37
|
+
const handleClick = async event => {
|
|
38
|
+
onClick?.(event);
|
|
39
|
+
if (event.defaultPrevented) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
await navigator.clipboard.writeText(text);
|
|
44
|
+
setIsCopied(true);
|
|
45
|
+
onCopySuccess?.(text);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
onCopyError?.(error);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
return /*#__PURE__*/jsx(Button, {
|
|
51
|
+
"aria-label": isCopied ? copiedLabel : label,
|
|
52
|
+
"data-cocso-component": "copy-button",
|
|
53
|
+
"data-copied": isCopied || undefined,
|
|
54
|
+
size: size,
|
|
55
|
+
svgOnly: true,
|
|
56
|
+
title: label,
|
|
57
|
+
type: "button",
|
|
58
|
+
variant: variant,
|
|
59
|
+
...props,
|
|
60
|
+
onClick: handleClick,
|
|
61
|
+
children: isCopied ? /*#__PURE__*/jsx(CheckIcon, {}) : /*#__PURE__*/jsx(ContentCopyIcon, {})
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { CopyButton };
|
|
@@ -5,11 +5,11 @@ import { ko } from 'date-fns/locale';
|
|
|
5
5
|
import { useState, useMemo } from 'react';
|
|
6
6
|
import DatePicker from 'react-datepicker';
|
|
7
7
|
import { cn } from '../../cn.mjs';
|
|
8
|
+
import { useYearMonthView, YearMonthView, CalendarTitle } from '../picker/year-month-view.mjs';
|
|
8
9
|
import styles from './date-time-picker.module.css.mjs';
|
|
9
10
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
10
11
|
import { Popover } from '../popover/popover.mjs';
|
|
11
12
|
import { Button } from '../button/button.mjs';
|
|
12
|
-
import { Typography } from '../typography/typography.mjs';
|
|
13
13
|
|
|
14
14
|
const isSameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
15
15
|
const atTime = (day, hours, minutes) => {
|
|
@@ -57,14 +57,24 @@ function DateTimePicker({
|
|
|
57
57
|
const [draft, setDraft] = useState(null);
|
|
58
58
|
const selected = value ?? draft;
|
|
59
59
|
|
|
60
|
-
// The month to open on: `minDate`'s
|
|
61
|
-
|
|
60
|
+
// The month to open on: the selection's, else `minDate`'s if it is still
|
|
61
|
+
// ahead of today, else today's.
|
|
62
|
+
const openingMonth = () => {
|
|
62
63
|
if (selected) {
|
|
63
|
-
return
|
|
64
|
+
return selected;
|
|
64
65
|
}
|
|
65
66
|
const now = new Date();
|
|
66
|
-
return minDate && minDate.getTime() > now.getTime() ? minDate :
|
|
67
|
-
}
|
|
67
|
+
return minDate && minDate.getTime() > now.getTime() ? minDate : now;
|
|
68
|
+
};
|
|
69
|
+
// The header opens a year-and-month grid, as in DayPicker — a date years
|
|
70
|
+
// away is a few clicks instead of one per month.
|
|
71
|
+
const calendar = useYearMonthView(openingMonth);
|
|
72
|
+
const handleOpenChange = next => {
|
|
73
|
+
setOpen(next);
|
|
74
|
+
if (next) {
|
|
75
|
+
calendar.reset(openingMonth());
|
|
76
|
+
}
|
|
77
|
+
};
|
|
68
78
|
|
|
69
79
|
// A bound that only applies on the day it falls on: on any other day the
|
|
70
80
|
// whole day is open. Without this a `minDate` of 3pm today would also cut
|
|
@@ -105,7 +115,7 @@ function DateTimePicker({
|
|
|
105
115
|
ref: ref,
|
|
106
116
|
...props,
|
|
107
117
|
children: /*#__PURE__*/jsxs(Popover, {
|
|
108
|
-
onOpenChange:
|
|
118
|
+
onOpenChange: handleOpenChange,
|
|
109
119
|
open: open,
|
|
110
120
|
children: [/*#__PURE__*/jsx(Popover.Trigger, {
|
|
111
121
|
render: trigger ?? /*#__PURE__*/jsx(Button, {
|
|
@@ -116,81 +126,94 @@ function DateTimePicker({
|
|
|
116
126
|
locale
|
|
117
127
|
}) : "Select date and time"
|
|
118
128
|
})
|
|
119
|
-
}), /*#__PURE__*/
|
|
129
|
+
}), /*#__PURE__*/jsxs(Popover.Content, {
|
|
120
130
|
"aria-label": "Select date and time",
|
|
121
131
|
className: styles.content,
|
|
122
|
-
children: /*#__PURE__*/jsx(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const day = date.getDay();
|
|
126
|
-
if (day === 0) {
|
|
127
|
-
return styles.sunday;
|
|
128
|
-
}
|
|
129
|
-
if (day === 6) {
|
|
130
|
-
return styles.saturday;
|
|
131
|
-
}
|
|
132
|
-
return "";
|
|
133
|
-
},
|
|
134
|
-
disabled: disabled,
|
|
135
|
-
filterTime: filterTime
|
|
136
|
-
// Six weeks always, for the same reason as DayPicker: a five-week month made
|
|
137
|
-
// the panel shorter, and paging into a six-week one could flip it above the trigger.
|
|
138
|
-
,
|
|
139
|
-
fixedHeight: true,
|
|
140
|
-
inline: true,
|
|
132
|
+
children: [/*#__PURE__*/jsx(YearMonthView, {
|
|
133
|
+
currentMonthRef: calendar.currentMonthRef,
|
|
134
|
+
hidden: calendar.view !== "month",
|
|
141
135
|
locale: locale,
|
|
142
136
|
maxDate: maxDate,
|
|
143
|
-
maxTime: bounds.maxTime,
|
|
144
137
|
minDate: minDate,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
138
|
+
minHeight: calendar.dayViewHeight,
|
|
139
|
+
onBack: () => calendar.changeView("day"),
|
|
140
|
+
onPick: calendar.jumpTo,
|
|
141
|
+
onYearChange: calendar.setViewDate,
|
|
142
|
+
selected: selected,
|
|
143
|
+
viewDate: calendar.viewDate
|
|
144
|
+
}), /*#__PURE__*/jsx("div", {
|
|
145
|
+
hidden: calendar.view !== "day",
|
|
146
|
+
children: /*#__PURE__*/jsx(DatePicker, {
|
|
147
|
+
dateFormat: dateFormat,
|
|
148
|
+
dayClassName: date => {
|
|
149
|
+
const day = date.getDay();
|
|
150
|
+
if (day === 0) {
|
|
151
|
+
return styles.sunday;
|
|
152
|
+
}
|
|
153
|
+
if (day === 6) {
|
|
154
|
+
return styles.saturday;
|
|
155
|
+
}
|
|
156
|
+
return "";
|
|
157
|
+
},
|
|
158
|
+
disabled: disabled,
|
|
159
|
+
filterTime: filterTime
|
|
160
|
+
// Six weeks always, for the same reason as DayPicker: a five-week month made
|
|
161
|
+
// the panel shorter, and paging into a six-week one could flip it above the trigger.
|
|
162
|
+
,
|
|
163
|
+
fixedHeight: true,
|
|
164
|
+
inline: true,
|
|
165
|
+
locale: locale,
|
|
166
|
+
maxDate: maxDate,
|
|
167
|
+
maxTime: bounds.maxTime,
|
|
168
|
+
minDate: minDate,
|
|
169
|
+
minTime: bounds.minTime,
|
|
170
|
+
onChange: handleChange,
|
|
171
|
+
onMonthChange: calendar.setViewDate,
|
|
172
|
+
openToDate: calendar.viewDate,
|
|
173
|
+
renderCustomHeader: ({
|
|
174
|
+
date,
|
|
175
|
+
decreaseMonth,
|
|
176
|
+
increaseMonth,
|
|
177
|
+
prevMonthButtonDisabled,
|
|
178
|
+
nextMonthButtonDisabled
|
|
179
|
+
}) => /*#__PURE__*/jsxs(Fragment, {
|
|
180
|
+
children: [/*#__PURE__*/jsx(CalendarTitle, {
|
|
181
|
+
date: date,
|
|
182
|
+
locale: locale,
|
|
183
|
+
onPress: panel => calendar.openMonths(date, panel),
|
|
184
|
+
ref: calendar.titleRef
|
|
185
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
186
|
+
className: styles.menu,
|
|
187
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
188
|
+
"aria-label": "Previous month",
|
|
189
|
+
className: styles.arrow,
|
|
190
|
+
disabled: prevMonthButtonDisabled,
|
|
191
|
+
onClick: decreaseMonth,
|
|
192
|
+
size: "x-small",
|
|
193
|
+
svgOnly: true,
|
|
194
|
+
type: "button",
|
|
195
|
+
variant: "outline",
|
|
196
|
+
children: /*#__PURE__*/jsx(ArrowIOSBackwardIcon, {})
|
|
197
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
198
|
+
"aria-label": "Next month",
|
|
199
|
+
className: styles.arrow,
|
|
200
|
+
disabled: nextMonthButtonDisabled,
|
|
201
|
+
onClick: increaseMonth,
|
|
202
|
+
size: "x-small",
|
|
203
|
+
svgOnly: true,
|
|
204
|
+
type: "button",
|
|
205
|
+
variant: "outline",
|
|
206
|
+
children: /*#__PURE__*/jsx(ArrowIOSForwardIcon, {})
|
|
207
|
+
})]
|
|
185
208
|
})]
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
})
|
|
209
|
+
}),
|
|
210
|
+
selected: selected ?? undefined,
|
|
211
|
+
showPopperArrow: false,
|
|
212
|
+
showTimeSelect: true,
|
|
213
|
+
timeCaption: timeCaption,
|
|
214
|
+
timeIntervals: timeIntervals
|
|
215
|
+
}, calendar.calendarKey)
|
|
216
|
+
})]
|
|
194
217
|
})]
|
|
195
218
|
})
|
|
196
219
|
});
|