pentatrion-design 0.0.10 → 0.0.12
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/CHANGELOG.md +8 -0
- package/components/input/Color.stories.tsx +18 -0
- package/components/input/Color.tsx +61 -0
- package/components/input/index.ts +1 -0
- package/components/notification/Notification.stories.tsx +5 -0
- package/components/notification/NotificationsProvider.tsx +1 -0
- package/components/snack/Snack.tsx +4 -1
- package/package.json +1 -1
- package/redux/notification/NotificationConsumer.tsx +9 -2
- package/components/notification/NotificationsProvider-ssr.tsx +0 -73
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Meta } from "@storybook/react";
|
|
2
|
+
import { Color } from "./Color";
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: "Components/Input/Color",
|
|
6
|
+
component: Color,
|
|
7
|
+
} satisfies Meta<typeof Color>;
|
|
8
|
+
export default meta;
|
|
9
|
+
|
|
10
|
+
export const Basic = () => {
|
|
11
|
+
return (
|
|
12
|
+
<div className="flex flex-col items-start gap-2">
|
|
13
|
+
<Color value="#fecdba" />
|
|
14
|
+
<Color value="#fecdba" label="300" />
|
|
15
|
+
<Color value="#fecdba" showValue={true} />
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ComponentProps, forwardRef, useImperativeHandle, useRef } from "react";
|
|
2
|
+
import type { ThemeColor } from "../../types.d";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { useRipple } from "../../hooks";
|
|
5
|
+
|
|
6
|
+
export interface ColorProps extends ComponentProps<"button"> {
|
|
7
|
+
withRipple?: boolean;
|
|
8
|
+
|
|
9
|
+
value?: string;
|
|
10
|
+
color?: ThemeColor;
|
|
11
|
+
label?: string;
|
|
12
|
+
showValue?: boolean;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Color = forwardRef<HTMLButtonElement, ColorProps>(
|
|
17
|
+
(
|
|
18
|
+
{
|
|
19
|
+
value,
|
|
20
|
+
withRipple = true,
|
|
21
|
+
color = "yellow",
|
|
22
|
+
label,
|
|
23
|
+
showValue = false,
|
|
24
|
+
className,
|
|
25
|
+
...rest
|
|
26
|
+
},
|
|
27
|
+
ref,
|
|
28
|
+
) => {
|
|
29
|
+
const valueToShow = label ?? (showValue ? value : null);
|
|
30
|
+
|
|
31
|
+
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
32
|
+
|
|
33
|
+
useImperativeHandle<HTMLButtonElement | null, HTMLButtonElement | null>(
|
|
34
|
+
ref,
|
|
35
|
+
() => buttonRef.current,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const ripples = useRipple(buttonRef);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<button
|
|
42
|
+
ref={buttonRef}
|
|
43
|
+
data-color={color}
|
|
44
|
+
className="p8n-input-text relative flex h-8 overflow-clip rounded-2xl p-1 outline-offset-[-1px]"
|
|
45
|
+
{...rest}
|
|
46
|
+
>
|
|
47
|
+
{withRipple && ripples}
|
|
48
|
+
<span
|
|
49
|
+
className={clsx(
|
|
50
|
+
"flex items-center justify-center rounded-2xl px-2",
|
|
51
|
+
valueToShow === null && "min-w-12",
|
|
52
|
+
className,
|
|
53
|
+
)}
|
|
54
|
+
style={{ backgroundColor: value }}
|
|
55
|
+
>
|
|
56
|
+
{valueToShow}
|
|
57
|
+
</span>
|
|
58
|
+
</button>
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
);
|
|
@@ -46,6 +46,11 @@ export const Context = () => {
|
|
|
46
46
|
<Button onClick={handleClick}>Show info notification</Button>
|
|
47
47
|
<Button onClick={throwError}>Throw custom error</Button>
|
|
48
48
|
<Button onClick={handle404Error}>Throw 404 fetch error</Button>
|
|
49
|
+
<div className="mt-96">
|
|
50
|
+
<a href="#" className="link">
|
|
51
|
+
link
|
|
52
|
+
</a>
|
|
53
|
+
</div>
|
|
49
54
|
</div>
|
|
50
55
|
);
|
|
51
56
|
};
|
package/package.json
CHANGED
|
@@ -15,7 +15,14 @@ export function NotificationConsumer({ children }: Props) {
|
|
|
15
15
|
if (!container.current) {
|
|
16
16
|
container.current = document.createElement("div");
|
|
17
17
|
container.current.id = nanoid();
|
|
18
|
-
container.current.classList.add(
|
|
18
|
+
container.current.classList.add(
|
|
19
|
+
"fixed",
|
|
20
|
+
"bottom-0",
|
|
21
|
+
"left-0",
|
|
22
|
+
"right-0",
|
|
23
|
+
"z-notification",
|
|
24
|
+
"pointer-events-none",
|
|
25
|
+
);
|
|
19
26
|
document.body.append(container.current);
|
|
20
27
|
}
|
|
21
28
|
|
|
@@ -36,7 +43,7 @@ export function NotificationConsumer({ children }: Props) {
|
|
|
36
43
|
<>
|
|
37
44
|
{children}
|
|
38
45
|
{createPortal(
|
|
39
|
-
<div className="mb-4 flex flex-col gap-4
|
|
46
|
+
<div className="mb-4 flex flex-col items-center gap-4">
|
|
40
47
|
{messages.map((message) => (
|
|
41
48
|
<Snack
|
|
42
49
|
key={message.id}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { createPortal } from "react-dom";
|
|
3
|
-
import {
|
|
4
|
-
NotificationsContext,
|
|
5
|
-
createNotificationsManager,
|
|
6
|
-
type NotificationsManager,
|
|
7
|
-
} from "./NotificationsContext";
|
|
8
|
-
import { Snack } from "../snack";
|
|
9
|
-
import { Message } from "../../types.d";
|
|
10
|
-
|
|
11
|
-
interface Props {
|
|
12
|
-
children: ReactNode;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function NotificationsProvider({ children }: Props) {
|
|
16
|
-
const [notifications, setNotifications] = useState<Message[]>([]);
|
|
17
|
-
const container = useRef<HTMLDivElement>(null!);
|
|
18
|
-
const [isMounted, setIsMounted] = useState(false);
|
|
19
|
-
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (!container.current) {
|
|
22
|
-
container.current = document.createElement("div");
|
|
23
|
-
container.current.id = Math.floor(Math.random() * 100000).toString();
|
|
24
|
-
/* .ll-snack-bar */
|
|
25
|
-
container.current.classList.add(
|
|
26
|
-
"fixed",
|
|
27
|
-
"bottom-0",
|
|
28
|
-
"left-0",
|
|
29
|
-
"right-0",
|
|
30
|
-
"z-notification",
|
|
31
|
-
);
|
|
32
|
-
document.body.append(container.current);
|
|
33
|
-
}
|
|
34
|
-
setIsMounted(true);
|
|
35
|
-
return () => {
|
|
36
|
-
container.current && container.current.remove();
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
39
|
-
|
|
40
|
-
const managerRef = useRef<NotificationsManager>();
|
|
41
|
-
|
|
42
|
-
if (typeof window === "undefined") {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!managerRef.current) {
|
|
47
|
-
managerRef.current = createNotificationsManager(setNotifications);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const manager = managerRef.current;
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<>
|
|
54
|
-
<NotificationsContext.Provider value={manager}>
|
|
55
|
-
{children}
|
|
56
|
-
</NotificationsContext.Provider>
|
|
57
|
-
{isMounted &&
|
|
58
|
-
createPortal(
|
|
59
|
-
/* snack-bar-inner */
|
|
60
|
-
<div className="mx-4 mb-4 flex flex-col items-center gap-4">
|
|
61
|
-
{notifications.map((props) => (
|
|
62
|
-
<Snack
|
|
63
|
-
{...props}
|
|
64
|
-
key={props.id}
|
|
65
|
-
onRemove={() => manager.removeNotification(props.id)}
|
|
66
|
-
/>
|
|
67
|
-
))}
|
|
68
|
-
</div>,
|
|
69
|
-
container.current,
|
|
70
|
-
)}
|
|
71
|
-
</>
|
|
72
|
-
);
|
|
73
|
-
}
|