@vrobots/storybook 0.1.43 → 0.1.45

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vrobots/storybook",
3
3
  "private": false,
4
- "version": "0.1.43",
4
+ "version": "0.1.45",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -30,7 +30,8 @@
30
30
  "react-dnd-html5-backend": "^16.0.1",
31
31
  "react-dnd-touch-backend": "^16.0.1",
32
32
  "react-dom": "^19.2.0",
33
- "react-icons": "^5.5.0"
33
+ "react-hook-form": "^7.71.2",
34
+ "react-icons": "^5.6.0"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@chromatic-com/storybook": "^5.0.0",
@@ -9,4 +9,4 @@ export interface IMenuProps {
9
9
  selected?: string;
10
10
  onClick?: (value: string) => void;
11
11
  }
12
- export declare const Menu: React.ForwardRefExoticComponent<IMenuProps & React.RefAttributes<unknown>>;
12
+ export declare const Menu: React.ForwardRefExoticComponent<IMenuProps & React.RefAttributes<HTMLDivElement>>;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { createListCollection, Listbox } from "@chakra-ui/react";
3
3
  import React, { forwardRef } from "react";
4
4
  import { useSelectedColorSchema } from "../hooks/useSelectedColorSchema";
5
- export const Menu = forwardRef(({ label, menuItems, selected = '', onClick, }) => {
5
+ export const Menu = forwardRef(({ label, menuItems, selected = '', onClick, }, ref) => {
6
6
  const frameworks = React.useMemo(() => createListCollection({
7
7
  items: menuItems || [],
8
8
  }), [menuItems]);
@@ -11,6 +11,6 @@ export const Menu = forwardRef(({ label, menuItems, selected = '', onClick, }) =
11
11
  const value = details.value[0];
12
12
  onClick?.(value);
13
13
  };
14
- return (_jsxs(Listbox.Root, { collection: frameworks, value: [selected], onValueChange: handleValueChange, pt: 4, children: [!!label && _jsx(Listbox.Label, { pl: 5, children: label }), _jsx(Listbox.Content, { border: 0, bgColor: 'transparent', children: frameworks.items.map((framework, i) => (_jsx(Listbox.Item, { item: framework, pl: 4, pr: 4, ...([selected].includes(framework.value) ? selectedColorSchema : undefined), children: _jsx(Listbox.ItemText, { children: framework.label }) }, `${framework.label} ${i + 1}`))) })] }));
14
+ return (_jsxs(Listbox.Root, { collection: frameworks, value: [selected], onValueChange: handleValueChange, pt: 4, ref: ref, children: [!!label && _jsx(Listbox.Label, { pl: 5, children: label }), _jsx(Listbox.Content, { border: 0, bgColor: 'transparent', children: frameworks.items.map((framework, i) => (_jsx(Listbox.Item, { item: framework, pl: 4, pr: 4, ...([selected].includes(framework.value) ? selectedColorSchema : undefined), children: _jsx(Listbox.ItemText, { children: framework.label }) }, `${framework.label} ${i + 1}`))) })] }));
15
15
  });
16
16
  Menu.displayName = 'Menu';
@@ -0,0 +1,12 @@
1
+ import { CardRootProps } from "@chakra-ui/react";
2
+ export interface ILoginCredentials {
3
+ emailAddress: string;
4
+ password: string;
5
+ }
6
+ export interface ILoginProps extends CardRootProps {
7
+ title?: string;
8
+ description?: string;
9
+ onLogin: (credentials: ILoginCredentials) => void;
10
+ }
11
+ declare const Login: ({ title, description, onLogin, ...props }: ILoginProps) => import("react/jsx-runtime").JSX.Element;
12
+ export default Login;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Button, Card, Field, Input, Stack } from "@chakra-ui/react";
3
+ import { useForm } from "react-hook-form";
4
+ import { PasswordInput } from "../ui/password-input";
5
+ import utils from "../../utils";
6
+ const Login = ({ title, description, onLogin, ...props }) => {
7
+ const { register, handleSubmit, formState: { errors }, } = useForm();
8
+ return (_jsx(Card.Root, { ...props, children: _jsxs(Card.Body, { children: [_jsx(Card.Title, { children: title || "Login" }), !!description && _jsx(Card.Description, { children: description }), _jsxs(Box, { as: "form", onSubmit: handleSubmit((data) => onLogin(data)), mt: 4, children: [_jsxs(Stack, { gap: "4", children: [_jsxs(Field.Root, { invalid: !!errors.emailAddress, required: true, children: [_jsx(Field.Label, { children: "Email Address" }), _jsx(Input, { ...register("emailAddress", {
9
+ required: "Please enter your email address",
10
+ pattern: {
11
+ value: /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
12
+ message: "Invalid email address"
13
+ }
14
+ }) }), _jsx(Field.ErrorText, { children: errors.emailAddress?.message })] }), _jsxs(Field.Root, { invalid: !!errors.password, children: [_jsx(Field.Label, { children: "Password" }), _jsx(PasswordInput, { ...register("password", {
15
+ required: "Please enter your password",
16
+ validate: (value) => utils.validation.password(value)
17
+ }) }), _jsx(Field.ErrorText, { as: "pre", children: errors.password?.message })] })] }), _jsx(Button, { type: "submit", colorScheme: "teal", width: "full", mt: 6, children: "Login" })] })] }) }));
18
+ };
19
+ export default Login;
@@ -0,0 +1,5 @@
1
+ declare const Form: {
2
+ (): null;
3
+ Login: ({ title, description, onLogin, ...props }: import("./Login").ILoginProps) => import("react/jsx-runtime").JSX.Element;
4
+ };
5
+ export default Form;
@@ -0,0 +1,4 @@
1
+ import Login from "./Login";
2
+ const Form = () => null;
3
+ Form.Login = Login;
4
+ export default Form;
@@ -11,3 +11,4 @@ export * from './Page';
11
11
  export * from './Section';
12
12
  export * from './Sidebar';
13
13
  export * from './Timeline';
14
+ export { default as Form } from './form';
@@ -11,3 +11,4 @@ export * from './Page';
11
11
  export * from './Section';
12
12
  export * from './Sidebar';
13
13
  export * from './Timeline';
14
+ export { default as Form } from './form';
@@ -0,0 +1,21 @@
1
+ import type { GroupProps, InputProps, StackProps } from "@chakra-ui/react";
2
+ import * as React from "react";
3
+ export interface PasswordVisibilityProps {
4
+ defaultVisible?: boolean;
5
+ visible?: boolean;
6
+ onVisibleChange?: (visible: boolean) => void;
7
+ visibilityIcon?: {
8
+ on: React.ReactNode;
9
+ off: React.ReactNode;
10
+ };
11
+ }
12
+ export interface PasswordInputProps extends InputProps, PasswordVisibilityProps {
13
+ rootProps?: GroupProps;
14
+ }
15
+ export declare const PasswordInput: React.ForwardRefExoticComponent<PasswordInputProps & React.RefAttributes<HTMLInputElement>>;
16
+ interface PasswordStrengthMeterProps extends StackProps {
17
+ max?: number;
18
+ value: number;
19
+ }
20
+ export declare const PasswordStrengthMeter: React.ForwardRefExoticComponent<PasswordStrengthMeterProps & React.RefAttributes<HTMLDivElement>>;
21
+ export {};
@@ -0,0 +1,44 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Box, HStack, IconButton, Input, InputGroup, Stack, mergeRefs, useControllableState, } from "@chakra-ui/react";
4
+ import * as React from "react";
5
+ import { LuEye, LuEyeOff } from "react-icons/lu";
6
+ export const PasswordInput = React.forwardRef(function PasswordInput(props, ref) {
7
+ const { rootProps, defaultVisible, visible: visibleProp, onVisibleChange, visibilityIcon = { on: _jsx(LuEye, {}), off: _jsx(LuEyeOff, {}) }, ...rest } = props;
8
+ const [visible, setVisible] = useControllableState({
9
+ value: visibleProp,
10
+ defaultValue: defaultVisible || false,
11
+ onChange: onVisibleChange,
12
+ });
13
+ const inputRef = React.useRef(null);
14
+ return (_jsx(InputGroup, { endElement: _jsx(VisibilityTrigger, { disabled: rest.disabled, onPointerDown: (e) => {
15
+ if (rest.disabled)
16
+ return;
17
+ if (e.button !== 0)
18
+ return;
19
+ e.preventDefault();
20
+ setVisible(!visible);
21
+ }, children: visible ? visibilityIcon.off : visibilityIcon.on }), ...rootProps, children: _jsx(Input, { ...rest, ref: mergeRefs(ref, inputRef), type: visible ? "text" : "password" }) }));
22
+ });
23
+ const VisibilityTrigger = React.forwardRef(function VisibilityTrigger(props, ref) {
24
+ return (_jsx(IconButton, { tabIndex: -1, ref: ref, me: "-2", aspectRatio: "square", size: "sm", variant: "ghost", height: "calc(100% - {spacing.2})", "aria-label": "Toggle password visibility", ...props }));
25
+ });
26
+ export const PasswordStrengthMeter = React.forwardRef(function PasswordStrengthMeter(props, ref) {
27
+ const { max = 4, value, ...rest } = props;
28
+ const percent = (value / max) * 100;
29
+ const { label, colorPalette } = getColorPalette(percent);
30
+ return (_jsxs(Stack, { align: "flex-end", gap: "1", ref: ref, ...rest, children: [_jsx(HStack, { width: "full", ...rest, children: Array.from({ length: max }).map((_, index) => (_jsx(Box, { height: "1", flex: "1", rounded: "sm", "data-selected": index < value ? "" : undefined, layerStyle: "fill.subtle", colorPalette: "gray", _selected: {
31
+ colorPalette,
32
+ layerStyle: "fill.solid",
33
+ } }, index))) }), label && _jsx(HStack, { textStyle: "xs", children: label })] }));
34
+ });
35
+ function getColorPalette(percent) {
36
+ switch (true) {
37
+ case percent < 33:
38
+ return { label: "Low", colorPalette: "red" };
39
+ case percent < 66:
40
+ return { label: "Medium", colorPalette: "orange" };
41
+ default:
42
+ return { label: "High", colorPalette: "green" };
43
+ }
44
+ }
@@ -0,0 +1,15 @@
1
+ import type { StoryObj } from '@storybook/react-vite';
2
+ declare const meta: {
3
+ title: string;
4
+ component: ({ title, description, onLogin, ...props }: import("../components/form/Login").ILoginProps) => import("react/jsx-runtime").JSX.Element;
5
+ tags: string[];
6
+ parameters: {
7
+ layout: string;
8
+ };
9
+ args: {
10
+ title: string;
11
+ };
12
+ };
13
+ export default meta;
14
+ type Story = StoryObj<typeof meta>;
15
+ export declare const Component: Story;
@@ -0,0 +1,20 @@
1
+ import { Form } from '../components';
2
+ const meta = {
3
+ title: 'Forms/Login',
4
+ component: Form.Login,
5
+ tags: ['autodocs'],
6
+ parameters: {
7
+ layout: 'fullscreen',
8
+ },
9
+ args: {
10
+ title: "Login",
11
+ }
12
+ };
13
+ export default meta;
14
+ export const Component = {
15
+ args: {
16
+ title: "Login Form",
17
+ description: "Please enter your credentials to continue",
18
+ onLogin: (data) => console.log(data)
19
+ }
20
+ };
@@ -1,7 +1,7 @@
1
1
  import type { StoryObj } from '@storybook/react-vite';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: import("react").ForwardRefExoticComponent<import("../components").IMenuProps & import("react").RefAttributes<unknown>>;
4
+ component: import("react").ForwardRefExoticComponent<import("../components").IMenuProps & import("react").RefAttributes<HTMLDivElement>>;
5
5
  tags: string[];
6
6
  parameters: {
7
7
  layout: string;
@@ -1,4 +1,3 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import owasp from 'owasp-password-strength-test';
3
2
  export const validation = {
4
3
  emailAddress: (emailAddress) => {
@@ -15,15 +14,16 @@ export const validation = {
15
14
  },
16
15
  maxChars: (label, value, max) => {
17
16
  const test = value.length <= max;
18
- return test || !value ? '' : `${label} must contain ${max} characters or less`;
17
+ return test || !value ? '' : `${label} must contain ${max} characters or less`;
19
18
  },
20
19
  password: (password) => {
21
20
  const result = owasp.test(password);
22
21
  if (result.errors.length) {
23
- const errors = result.errors.map((error, key) => (_jsxs("span", { children: [_jsx("span", { children: error.replace('The password', '• ').replace('.', '') }), _jsx("br", {})] }, `span-error-${key}`)));
24
- return errors;
22
+ const errors = result.errors.map((error, key) => error.replace('The password', '•').replace('.', ''));
23
+ console.log(errors);
24
+ return errors.join('\n');
25
25
  }
26
- return '';
26
+ return true;
27
27
  },
28
28
  mobile: () => {
29
29
  let check = false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vrobots/storybook",
3
3
  "private": false,
4
- "version": "0.1.43",
4
+ "version": "0.1.45",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -30,7 +30,8 @@
30
30
  "react-dnd-html5-backend": "^16.0.1",
31
31
  "react-dnd-touch-backend": "^16.0.1",
32
32
  "react-dom": "^19.2.0",
33
- "react-icons": "^5.5.0"
33
+ "react-hook-form": "^7.71.2",
34
+ "react-icons": "^5.6.0"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@chromatic-com/storybook": "^5.0.0",