@a-type/ui 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/components/actions/ActionBar.tsx +38 -0
- package/src/components/actions/ActionButton.tsx +59 -0
- package/src/components/actions/index.ts +2 -0
- package/src/components/actions.ts +1 -0
- package/src/components/avatar/Avatar.tsx +62 -0
- package/src/components/avatar/AvatarList.tsx +71 -0
- package/src/components/avatar/index.ts +2 -0
- package/src/components/avatar.ts +1 -0
- package/src/components/button/Button.stories.tsx +20 -0
- package/src/components/button/Button.tsx +66 -0
- package/src/components/button/ConfirmedButton.tsx +66 -0
- package/src/components/button/classes.tsx +56 -0
- package/src/components/button/index.ts +3 -0
- package/src/components/button.ts +1 -0
- package/src/components/camera/Camera.stories.tsx +40 -0
- package/src/components/camera/Camera.tsx +215 -0
- package/src/components/camera/index.ts +1 -0
- package/src/components/camera.ts +1 -0
- package/src/components/card/Card.stories.tsx +41 -0
- package/src/components/card/Card.tsx +68 -0
- package/src/components/card/index.ts +1 -0
- package/src/components/card.ts +1 -0
- package/src/components/checkbox/Checkbox.tsx +46 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/checkbox.ts +1 -0
- package/src/components/chip/Chip.tsx +29 -0
- package/src/components/chip/index.ts +1 -0
- package/src/components/chip.ts +1 -0
- package/src/components/collapsible/Collapsible.tsx +48 -0
- package/src/components/collapsible/index.ts +1 -0
- package/src/components/collapsible.ts +1 -0
- package/src/components/colorPicker/ColorPicker.tsx +82 -0
- package/src/components/colorPicker/index.ts +1 -0
- package/src/components/colorPicker.ts +1 -0
- package/src/components/contextMenu/contextMenu.tsx +43 -0
- package/src/components/contextMenu.ts +1 -0
- package/src/components/dialog/Dialog.stories.tsx +38 -0
- package/src/components/dialog/Dialog.tsx +267 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/dialog.ts +1 -0
- package/src/components/divider/Divider.tsx +26 -0
- package/src/components/divider/index.ts +1 -0
- package/src/components/divider.ts +1 -0
- package/src/components/dropdownMenu/DropdownMenu.stories.tsx +47 -0
- package/src/components/dropdownMenu/DropdownMenu.tsx +89 -0
- package/src/components/dropdownMenu/index.ts +1 -0
- package/src/components/dropdownMenu.ts +1 -0
- package/src/components/errorBoundary/ErrorBoundary.tsx +23 -0
- package/src/components/errorBoundary/index.ts +1 -0
- package/src/components/errorBoundary.ts +1 -0
- package/src/components/forms/Form.tsx +9 -0
- package/src/components/forms/FormikForm.tsx +41 -0
- package/src/components/forms/SubmitButton.tsx +15 -0
- package/src/components/forms/TextField.tsx +112 -0
- package/src/components/forms/index.tsx +4 -0
- package/src/components/forms.ts +1 -0
- package/src/components/icon/Icon.tsx +28 -0
- package/src/components/icon/generated/IconSpritesheet.tsx +442 -0
- package/src/components/icon/generated/iconNames.ts +44 -0
- package/src/components/icon/index.ts +3 -0
- package/src/components/icon.ts +1 -0
- package/src/components/imageUploader/ImageUploader.stories.tsx +39 -0
- package/src/components/imageUploader/ImageUploader.tsx +203 -0
- package/src/components/imageUploader/UploadIcon.tsx +23 -0
- package/src/components/imageUploader/index.ts +1 -0
- package/src/components/imageUploader.ts +1 -0
- package/src/components/infiniteLoadTrigger/InfiniteLoadTrigger.tsx +38 -0
- package/src/components/infiniteLoadTrigger.ts +1 -0
- package/src/components/input/Input.stories.tsx +17 -0
- package/src/components/input/Input.tsx +32 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input.ts +1 -0
- package/src/components/layouts/PageContent.tsx +51 -0
- package/src/components/layouts/PageFixedArea.tsx +17 -0
- package/src/components/layouts/PageNav.tsx +23 -0
- package/src/components/layouts/PageNowPlaying.tsx +24 -0
- package/src/components/layouts/PageRoot.tsx +29 -0
- package/src/components/layouts/PageSection.tsx +23 -0
- package/src/components/layouts/index.tsx +6 -0
- package/src/components/layouts.ts +1 -0
- package/src/components/liveUpdateTextField/LiveUpdateTextField.tsx +132 -0
- package/src/components/liveUpdateTextField/index.ts +1 -0
- package/src/components/liveUpdateTextField.ts +1 -0
- package/src/components/navBar/NavBar.tsx +59 -0
- package/src/components/navBar/index.ts +1 -0
- package/src/components/navBar.ts +1 -0
- package/src/components/note/Note.tsx +21 -0
- package/src/components/note/index.ts +1 -0
- package/src/components/note.ts +1 -0
- package/src/components/numberStepper/NumberStepper.stories.tsx +21 -0
- package/src/components/numberStepper/NumberStepper.tsx +74 -0
- package/src/components/numberStepper/index.ts +1 -0
- package/src/components/numberStepper.ts +1 -0
- package/src/components/particles/ParticleContext.tsx +11 -0
- package/src/components/particles/ParticleLayer.stories.tsx +46 -0
- package/src/components/particles/ParticleLayer.tsx +28 -0
- package/src/components/particles/index.ts +7 -0
- package/src/components/particles/particlesState.ts +502 -0
- package/src/components/particles.ts +1 -0
- package/src/components/peek/Peek.tsx +74 -0
- package/src/components/peek/index.ts +1 -0
- package/src/components/peek.ts +1 -0
- package/src/components/popover/Popover.tsx +84 -0
- package/src/components/popover/index.ts +1 -0
- package/src/components/popover.ts +1 -0
- package/src/components/relativeTime/RelativeTime.tsx +43 -0
- package/src/components/relativeTime/index.ts +1 -0
- package/src/components/relativeTime.ts +1 -0
- package/src/components/richEditor/EditorContent.tsx +4 -0
- package/src/components/richEditor/RichEditor.tsx +38 -0
- package/src/components/richEditor/index.ts +1 -0
- package/src/components/richEditor.ts +1 -0
- package/src/components/select/Select.tsx +247 -0
- package/src/components/select/index.ts +1 -0
- package/src/components/select.ts +1 -0
- package/src/components/skeletons/skeletons.tsx +27 -0
- package/src/components/skeletons.ts +1 -0
- package/src/components/spinner/Spinner.tsx +59 -0
- package/src/components/spinner/index.ts +1 -0
- package/src/components/spinner.ts +1 -0
- package/src/components/switch/Switch.tsx +23 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/switch.ts +1 -0
- package/src/components/tabs/tabs.tsx +18 -0
- package/src/components/tabs.ts +1 -0
- package/src/components/textArea/TextArea.stories.tsx +21 -0
- package/src/components/textArea/TextArea.tsx +58 -0
- package/src/components/textArea/index.ts +1 -0
- package/src/components/textArea.ts +1 -0
- package/src/components/toggleGroup/toggleGroup.tsx +11 -0
- package/src/components/toggleGroup.ts +1 -0
- package/src/components/tooltip/Tooltip.tsx +56 -0
- package/src/components/tooltip/index.ts +1 -0
- package/src/components/tooltip.ts +1 -0
- package/src/components/typography/index.ts +1 -0
- package/src/components/typography/typography.tsx +18 -0
- package/src/components/typography.ts +1 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useMergedRef.ts +14 -0
- package/src/hooks/useOnUnmount.ts +20 -0
- package/src/hooks/useSize.ts +164 -0
- package/src/hooks/useStableCallback.ts +11 -0
- package/src/hooks/useToggle.tsx +9 -0
- package/src/hooks/useVisualViewportOffset.ts +35 -0
- package/src/hooks/withClassName.tsx +21 -0
- package/src/hooks.ts +1 -0
- package/src/uno.preset.ts +767 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
|
+
import { useStableCallback } from './useStableCallback.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calls a callback with an element when it is unmounted.
|
|
6
|
+
* @returns a ref to pass to the component
|
|
7
|
+
*/
|
|
8
|
+
export function useOnUnmount(callback: (el: HTMLElement) => void) {
|
|
9
|
+
const stableCallback = useStableCallback(callback);
|
|
10
|
+
|
|
11
|
+
const ref = useRef<HTMLElement | null>(null);
|
|
12
|
+
|
|
13
|
+
return useCallback((el: HTMLElement | null) => {
|
|
14
|
+
console.log(el);
|
|
15
|
+
if (ref.current && !el) {
|
|
16
|
+
stableCallback(ref.current);
|
|
17
|
+
}
|
|
18
|
+
ref.current = el;
|
|
19
|
+
}, []);
|
|
20
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { debounce } from '@a-type/utils';
|
|
2
|
+
import { RefObject, useLayoutEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { useStableCallback } from './useStableCallback.js';
|
|
4
|
+
interface ResizeObserverEntry {
|
|
5
|
+
target: Element;
|
|
6
|
+
}
|
|
7
|
+
type ResizeObserverCallback = (entries: ResizeObserverEntry[]) => void;
|
|
8
|
+
export declare class ResizeObserver {
|
|
9
|
+
constructor(callback: ResizeObserverCallback);
|
|
10
|
+
observe(target: Element): void;
|
|
11
|
+
unobserve(target: Element): void;
|
|
12
|
+
disconnect(): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useSize<E extends HTMLElement>(
|
|
16
|
+
callback: (payload: { width: number; height: number }) => void,
|
|
17
|
+
) {
|
|
18
|
+
const ref = useRef<E>(null);
|
|
19
|
+
const cb = useStableCallback(callback);
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
const target = ref.current;
|
|
22
|
+
if (!target) {
|
|
23
|
+
return () => {
|
|
24
|
+
//
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
28
|
+
entries.forEach((entry) => {
|
|
29
|
+
cb({
|
|
30
|
+
width: entry.target.clientWidth,
|
|
31
|
+
height: entry.target.clientHeight,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
resizeObserver.observe(target);
|
|
36
|
+
return () => {
|
|
37
|
+
resizeObserver.unobserve(target);
|
|
38
|
+
resizeObserver.disconnect();
|
|
39
|
+
};
|
|
40
|
+
}, [ref, cb]);
|
|
41
|
+
return ref;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function useSizeCssVars<E extends HTMLElement>(
|
|
45
|
+
debounceMs?: number,
|
|
46
|
+
applyToRef?: RefObject<HTMLElement>,
|
|
47
|
+
propertyNames?: { width: string; height: string },
|
|
48
|
+
) {
|
|
49
|
+
const update = useMemo(() => {
|
|
50
|
+
const doupdate = ({ width, height }: { width: number; height: number }) => {
|
|
51
|
+
const usedRef = applyToRef || ref;
|
|
52
|
+
usedRef.current?.style.setProperty(
|
|
53
|
+
propertyNames?.width ?? '--width',
|
|
54
|
+
width + 'px',
|
|
55
|
+
);
|
|
56
|
+
usedRef.current?.style.setProperty(
|
|
57
|
+
propertyNames?.height ?? '--height',
|
|
58
|
+
height + 'px',
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
if (debounceMs) {
|
|
62
|
+
return debounce(doupdate, debounceMs);
|
|
63
|
+
} else {
|
|
64
|
+
return doupdate;
|
|
65
|
+
}
|
|
66
|
+
}, [debounceMs, applyToRef, propertyNames?.width, propertyNames?.height]);
|
|
67
|
+
const ref = useSize<E>(update);
|
|
68
|
+
return ref;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function useBounds<E extends HTMLElement>(
|
|
72
|
+
callback: (payload: {
|
|
73
|
+
left: number;
|
|
74
|
+
top: number;
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
}) => void,
|
|
78
|
+
) {
|
|
79
|
+
const ref = useRef<E>(null);
|
|
80
|
+
const cb = useStableCallback(callback);
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
const target = ref.current;
|
|
83
|
+
if (!target) {
|
|
84
|
+
return () => {
|
|
85
|
+
//
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
89
|
+
entries.forEach((entry) => {
|
|
90
|
+
const { left, top, width, height } =
|
|
91
|
+
entry.target.getBoundingClientRect();
|
|
92
|
+
cb({ left, top, width, height });
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
resizeObserver.observe(target);
|
|
96
|
+
return () => {
|
|
97
|
+
resizeObserver.unobserve(target);
|
|
98
|
+
resizeObserver.disconnect();
|
|
99
|
+
};
|
|
100
|
+
}, [ref, cb]);
|
|
101
|
+
return ref;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function useBoundsCssVars<E extends HTMLElement>(
|
|
105
|
+
debounceMs?: number,
|
|
106
|
+
applyToRef?: RefObject<HTMLElement>,
|
|
107
|
+
propertyNames?: {
|
|
108
|
+
left: string;
|
|
109
|
+
top: string;
|
|
110
|
+
width: string;
|
|
111
|
+
height: string;
|
|
112
|
+
ready: string;
|
|
113
|
+
},
|
|
114
|
+
) {
|
|
115
|
+
const update = useMemo(() => {
|
|
116
|
+
const doupdate = ({
|
|
117
|
+
left,
|
|
118
|
+
top,
|
|
119
|
+
width,
|
|
120
|
+
height,
|
|
121
|
+
}: {
|
|
122
|
+
left: number;
|
|
123
|
+
top: number;
|
|
124
|
+
width: number;
|
|
125
|
+
height: number;
|
|
126
|
+
}) => {
|
|
127
|
+
const usedRef = applyToRef || ref;
|
|
128
|
+
usedRef.current?.style.setProperty(
|
|
129
|
+
propertyNames?.left ?? '--left',
|
|
130
|
+
left + 'px',
|
|
131
|
+
);
|
|
132
|
+
usedRef.current?.style.setProperty(
|
|
133
|
+
propertyNames?.top ?? '--top',
|
|
134
|
+
top + 'px',
|
|
135
|
+
);
|
|
136
|
+
usedRef.current?.style.setProperty(
|
|
137
|
+
propertyNames?.width ?? '--width',
|
|
138
|
+
width + 'px',
|
|
139
|
+
);
|
|
140
|
+
usedRef.current?.style.setProperty(
|
|
141
|
+
propertyNames?.height ?? '--height',
|
|
142
|
+
height + 'px',
|
|
143
|
+
);
|
|
144
|
+
usedRef.current?.style.setProperty(
|
|
145
|
+
propertyNames?.ready ?? '--ready',
|
|
146
|
+
'1',
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
if (debounceMs) {
|
|
150
|
+
return debounce(doupdate, debounceMs);
|
|
151
|
+
} else {
|
|
152
|
+
return doupdate;
|
|
153
|
+
}
|
|
154
|
+
}, [
|
|
155
|
+
debounceMs,
|
|
156
|
+
applyToRef,
|
|
157
|
+
propertyNames?.left,
|
|
158
|
+
propertyNames?.top,
|
|
159
|
+
propertyNames?.width,
|
|
160
|
+
propertyNames?.height,
|
|
161
|
+
]);
|
|
162
|
+
const ref = useBounds<E>(update);
|
|
163
|
+
return ref;
|
|
164
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useStableCallback<Fn extends (...args: any[]) => any>(
|
|
4
|
+
callback: Fn | undefined,
|
|
5
|
+
) {
|
|
6
|
+
const ref = useRef(callback);
|
|
7
|
+
useMemo(() => {
|
|
8
|
+
ref.current = callback;
|
|
9
|
+
}, [callback]);
|
|
10
|
+
return useCallback((...args: any[]) => ref.current?.(...args), []);
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useToggle(
|
|
4
|
+
initialValue: boolean = false,
|
|
5
|
+
): [boolean, () => void] {
|
|
6
|
+
const [value, setValue] = useState(initialValue);
|
|
7
|
+
const toggle = useCallback(() => setValue((v) => !v), []);
|
|
8
|
+
return [value, toggle];
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Applies bottom offset px as a CSS custom property to the document root.
|
|
5
|
+
*/
|
|
6
|
+
export function useVisualViewportOffset() {
|
|
7
|
+
const viewport = window.visualViewport;
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!viewport) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const update = () => {
|
|
15
|
+
document.documentElement.style.setProperty(
|
|
16
|
+
'--viewport-bottom-offset',
|
|
17
|
+
`${window.innerHeight - viewport.height}px`,
|
|
18
|
+
);
|
|
19
|
+
document.documentElement.style.setProperty(
|
|
20
|
+
'--viewport-height',
|
|
21
|
+
`${viewport.height}px`,
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
update();
|
|
26
|
+
|
|
27
|
+
window.addEventListener('scroll', update, { passive: true });
|
|
28
|
+
viewport.addEventListener('resize', update);
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
viewport.removeEventListener('resize', update);
|
|
32
|
+
window.removeEventListener('scroll', update);
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import {
|
|
3
|
+
ComponentPropsWithRef,
|
|
4
|
+
ComponentType,
|
|
5
|
+
ElementType,
|
|
6
|
+
FunctionComponent,
|
|
7
|
+
forwardRef,
|
|
8
|
+
} from 'react';
|
|
9
|
+
|
|
10
|
+
export function withClassName<T extends ComponentType<any> | ElementType<any>>(
|
|
11
|
+
Component: T,
|
|
12
|
+
...cs: Parameters<typeof classNames>
|
|
13
|
+
): FunctionComponent<ComponentPropsWithRef<T>> {
|
|
14
|
+
const WithClassName = forwardRef<any, any>((props, ref) => {
|
|
15
|
+
const { className, ...rest } = props;
|
|
16
|
+
return (
|
|
17
|
+
<Component ref={ref} {...rest} className={classNames(cs, className)} />
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
return WithClassName as any;
|
|
21
|
+
}
|
package/src/hooks.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks/index.js';
|