@zuzjs/ui 0.4.7 → 0.4.8

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 CHANGED
@@ -1 +1,44 @@
1
- # zuzjs-ui
1
+ # @zuzjs/ui
2
+
3
+ The `@zuzjs/ui` library provides a collection of reusable components and blocks designed to streamline your development process. It also includes an automatic CSS generator to help you maintain consistent styling across your application.
4
+
5
+ ## Features
6
+
7
+ - **Components**: A variety of pre-built UI components to speed up your development.
8
+ - **Blocks**: Modular blocks that can be easily integrated into your projects.
9
+ - **Auto CSS Generator**: Automatically generates CSS to ensure consistent and maintainable styles.
10
+
11
+ ## Installation
12
+
13
+ To install the `@zuzjs/ui` library, use the following command:
14
+
15
+ ```bash
16
+ npm install @zuzjs/ui
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Import the components and blocks you need and start building your UI:
22
+
23
+ ```javascript
24
+ import { Box, Button, Text } from '@zuzjs/ui';
25
+
26
+ function App() {
27
+ return (
28
+ <Box as={`w:100 h:100 bg:red`}>
29
+ <Button as={`s:18 bold tac`}>Click Me</Button>
30
+ <Text as={`s:18 tac`}>Hello World!</Text>
31
+ </Box>
32
+ );
33
+ }
34
+ ```
35
+
36
+ The auto CSS generator will handle the styling for you, ensuring a cohesive look and feel.
37
+
38
+ ## Documentation
39
+
40
+ Documention in progress.
41
+
42
+ ## License
43
+
44
+ This project is licensed under the MIT License.
@@ -5,6 +5,7 @@ export interface DrawerProps {
5
5
  speed?: number;
6
6
  from?: DRAWER_SIDE;
7
7
  children: string | ReactNode | ReactNode[];
8
+ prerender?: boolean;
8
9
  }
9
10
  export interface DrawerHandler {
10
11
  open: () => void;
@@ -3,9 +3,10 @@ import { forwardRef, useImperativeHandle, useMemo, useRef, useState } from "reac
3
3
  import With from "./base";
4
4
  import { DRAWER_SIDE, TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
5
5
  const Drawer = forwardRef((props, ref) => {
6
- const { as, from, speed, children, ...rest } = props;
6
+ const { as, from, speed, children, prerender, ...rest } = props;
7
7
  const [visible, setVisible] = useState(false);
8
8
  const divRef = useRef(null);
9
+ const render = useMemo(() => prerender || true, []);
9
10
  const style = useMemo(() => {
10
11
  switch (from) {
11
12
  case DRAWER_SIDE.Left:
@@ -41,6 +42,6 @@ const Drawer = forwardRef((props, ref) => {
41
42
  when: visible,
42
43
  curve: TRANSITION_CURVES.EaseInOut,
43
44
  duration: speed || .5,
44
- }, ...rest, children: [from == DRAWER_SIDE.Top || from == DRAWER_SIDE.Bottom ? _jsx(With, { className: "drawer-handle" }) : null, children] })] });
45
+ }, ...rest, children: [from == DRAWER_SIDE.Top || from == DRAWER_SIDE.Bottom ? _jsx(With, { className: "drawer-handle" }) : null, (render || visible) && children] })] });
45
46
  });
46
47
  export default Drawer;
@@ -1,10 +1,15 @@
1
1
  import React from 'react';
2
2
  import { animationProps } from "./base";
3
- declare const TextWheel: React.ForwardRefExoticComponent<{
3
+ export interface WheelProps {
4
4
  as?: string;
5
5
  direction?: `up` | `down`;
6
- value: number | string;
6
+ value?: number | string;
7
7
  color?: string;
8
8
  animate?: animationProps;
9
- } & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
9
+ }
10
+ export interface WheelHandler {
11
+ setValue: (v: number | string) => void;
12
+ updateValue: (v: number | string) => void;
13
+ }
14
+ declare const TextWheel: React.ForwardRefExoticComponent<WheelProps & React.RefAttributes<WheelHandler>>;
10
15
  export default TextWheel;
@@ -1,9 +1,35 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useImperativeHandle, useRef, useState } from 'react';
2
3
  import { forwardRef } from 'react';
3
4
  import With from "./base";
4
5
  const TextWheel = forwardRef((props, ref) => {
5
6
  const { as, value, color, direction, ...rest } = props;
6
- return _jsxs(With, { className: `text-wheel flex aic rel`, "aria-hidden": true, as: as, ref: ref, ...rest, children: [value.toString().split('').map((char, index) => {
7
+ const divRef = useRef(null);
8
+ const [_value, _setValue] = useState(value || 0);
9
+ useImperativeHandle(ref, () => ({
10
+ updateValue(v) {
11
+ if (_value != v || _value.toString().length != v.toString().length) {
12
+ _setValue(v);
13
+ }
14
+ },
15
+ setValue(v) {
16
+ this.updateValue(v);
17
+ if (divRef.current) {
18
+ const chars = v.toString().split('');
19
+ divRef.current.querySelectorAll('.wheel-char').forEach((charElement, index) => {
20
+ const char = chars[index];
21
+ if (charElement instanceof HTMLElement) {
22
+ charElement.setAttribute('data-value', char);
23
+ const track = charElement.querySelector('.wheel-char-track');
24
+ if (track instanceof HTMLElement) {
25
+ track.style.setProperty('--v', char);
26
+ }
27
+ }
28
+ });
29
+ }
30
+ }
31
+ }));
32
+ return _jsxs(With, { className: `text-wheel flex aic rel`, "aria-hidden": true, as: as, ref: divRef, ...rest, children: [(_value || 0).toString().split('').map((char, index) => {
7
33
  if (isNaN(parseInt(char, 10))) {
8
34
  return _jsx(With, { tag: `span`, className: "wheel-char wheel-char-symbol grid", children: char }, `wheel-char-${index}`);
9
35
  }
@@ -1,4 +1,5 @@
1
1
  export { default as useDevice } from './useDevice';
2
2
  export { default as useDimensions } from './useDimensions';
3
3
  export { default as useMounted } from './useMounted';
4
+ export { default as useWindowFocus } from './useWindowFocus';
4
5
  export * from './usePubSub';
@@ -1,4 +1,5 @@
1
1
  export { default as useDevice } from './useDevice';
2
2
  export { default as useDimensions } from './useDimensions';
3
3
  export { default as useMounted } from './useMounted';
4
+ export { default as useWindowFocus } from './useWindowFocus';
4
5
  export * from './usePubSub';
@@ -0,0 +1,2 @@
1
+ declare const useWindowFocus: (delay?: number) => boolean;
2
+ export default useWindowFocus;
@@ -0,0 +1,11 @@
1
+ import { useState, useEffect } from 'react';
2
+ const useWindowFocus = (delay = 100) => {
3
+ const [focused, setFocus] = useState(true);
4
+ useEffect(() => {
5
+ window.addEventListener(`focusin`, () => setFocus(true));
6
+ window.addEventListener(`focusout`, () => setFocus(false));
7
+ return () => setFocus(false);
8
+ }, [delay]);
9
+ return focused;
10
+ };
11
+ export default useWindowFocus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuzjs/ui",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "keywords": [
5
5
  "react",
6
6
  "zuz",