@saas-ui/modals 0.1.1 → 0.2.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/CHANGELOG.md +27 -0
- package/dist/form.d.ts +26 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -353
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/menu.d.ts +12 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/modal.d.ts +6 -8
- package/dist/modal.d.ts.map +1 -1
- package/dist/provider.d.ts +5 -3
- package/dist/provider.d.ts.map +1 -1
- package/package.json +7 -2
- package/src/form.tsx +104 -0
- package/src/index.ts +2 -0
- package/src/menu.tsx +87 -0
- package/src/modal.tsx +9 -12
- package/src/provider.tsx +25 -3
- package/.turbo/turbo-build.log +0 -6
- package/stories/modal.stories.tsx +0 -158
- package/tests/modal.test.tsx +0 -1
- package/tsconfig.json +0 -12
package/dist/index.modern.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/dialog.tsx","../src/drawer.tsx","../src/modal.tsx","../src/provider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n AlertDialog,\n AlertDialogBody,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogContent,\n AlertDialogOverlay,\n AlertDialogProps,\n} from '@chakra-ui/react'\n\nimport {\n ButtonGroup,\n ButtonGroupProps,\n Button,\n ButtonProps,\n} from '@saas-ui/button'\n\nexport interface ConfirmDialogProps\n extends Omit<AlertDialogProps, 'leastDestructiveRef'> {\n /**\n * The dialog title\n */\n title?: React.ReactNode\n /**\n * The cancel button label\n */\n cancelLabel?: React.ReactNode\n /**\n * The confirm button label\n */\n confirmLabel?: React.ReactNode\n /**\n * The cancel button props\n */\n cancelProps?: ButtonProps\n /**\n * The confirm button props\n */\n confirmProps?: ButtonProps\n /**\n * The button group props\n */\n buttonGroupProps?: ButtonGroupProps\n /**\n * Close the dialog on cancel\n * @default true\n */\n closeOnCancel?: boolean\n /**\n * Close the dialog on confirm\n * @default true\n */\n closeOnConfirm?: boolean\n /**\n * Defines which button gets initial focus\n * https://www.w3.org/TR/wai-aria-practices/#alertdialog\n */\n leastDestructiveFocus?: 'cancel' | 'confirm'\n /**\n * Function that's called when cancel is clicked\n */\n onCancel?: () => void\n /**\n * Function that's called when confirm is clicked\n */\n onConfirm?: () => void\n}\n\nexport const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {\n const {\n title,\n cancelLabel = 'Cancel',\n confirmLabel = 'Confirm',\n cancelProps,\n confirmProps,\n buttonGroupProps,\n isOpen,\n closeOnCancel = true,\n closeOnConfirm = true,\n leastDestructiveFocus = 'cancel',\n onClose,\n onCancel,\n onConfirm,\n children,\n ...rest\n } = props\n\n const cancelRef = React.useRef(null)\n const confirmRef = React.useRef(null)\n\n return (\n <AlertDialog\n isOpen={isOpen}\n onClose={onClose}\n {...rest}\n leastDestructiveRef={\n leastDestructiveFocus === 'cancel' ? cancelRef : confirmRef\n }\n >\n <AlertDialogOverlay>\n <AlertDialogContent>\n <AlertDialogHeader>{title}</AlertDialogHeader>\n\n <AlertDialogBody>{children}</AlertDialogBody>\n\n <AlertDialogFooter>\n <ButtonGroup {...buttonGroupProps}>\n <Button\n ref={cancelRef}\n {...cancelProps}\n onClick={() => {\n onCancel?.()\n\n closeOnCancel && onClose()\n }}\n >\n Cancel\n </Button>\n <Button\n ref={confirmRef}\n {...confirmProps}\n onClick={() => {\n onConfirm?.()\n\n closeOnConfirm && onClose()\n }}\n >\n Confirm\n </Button>\n </ButtonGroup>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialogOverlay>\n </AlertDialog>\n )\n}\n","import * as React from 'react'\n\nimport {\n Drawer as ChakraDrawer,\n DrawerOverlay,\n DrawerContent,\n DrawerHeader,\n DrawerFooter,\n DrawerBody,\n DrawerCloseButton,\n DrawerProps as ChakraDrawerProps,\n} from '@chakra-ui/react'\n\nexport interface BaseDrawerProps extends Omit<ChakraDrawerProps, 'children'> {\n /**\n * The drawer title\n */\n title: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overflow\n */\n hideOverlay?: boolean\n children?: React.ReactNode\n}\n\nexport const BaseDrawer: React.FC<BaseDrawerProps> = (props) => {\n const {\n title,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <DrawerOverlay />}\n <DrawerContent>\n <DrawerHeader>{title}</DrawerHeader>\n {!hideCloseButton && <DrawerCloseButton />}\n {children}\n </DrawerContent>\n </ChakraDrawer>\n )\n}\n\nexport interface DrawerProps extends BaseDrawerProps {\n /**\n * Drawer footer content, wrapped with `DrawerFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Drawer: React.FC<DrawerProps> = (props) => {\n const { footer, children, ...rest } = props\n return (\n <BaseDrawer {...rest}>\n <DrawerBody>{children}</DrawerBody>\n\n {footer && <DrawerFooter>{footer}</DrawerFooter>}\n </BaseDrawer>\n )\n}\n","import * as React from 'react'\n\nimport {\n Modal as ChakraModal,\n ModalOverlay,\n ModalContent,\n ModalHeader,\n ModalFooter,\n ModalBody,\n ModalCloseButton,\n ModalProps as ChakraModalProps,\n} from '@chakra-ui/react'\n\nexport interface BaseModalProps extends ChakraModalProps {\n /**\n * The modal title\n */\n title: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overlay\n */\n hideOverlay?: boolean\n}\n\nexport const BaseModal: React.FC<BaseModalProps> = (props) => {\n const {\n title,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <ModalOverlay />}\n <ModalContent>\n <ModalHeader>{title}</ModalHeader>\n {!hideCloseButton && <ModalCloseButton />}\n {children}\n </ModalContent>\n </ChakraModal>\n )\n}\n\nexport interface ModalProps extends BaseModalProps {\n /**\n * The modal footer, wrapped with `ModalFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Modal: React.FC<ModalProps> = (props) => {\n const { children, footer, ...rest } = props\n return (\n <BaseModal {...rest}>\n <ModalBody>{children}</ModalBody>\n\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport { Modal, ModalProps } from './modal'\nimport { Drawer, DrawerProps } from './drawer'\nimport { ConfirmDialog, ConfirmDialogProps } from './dialog'\n\nexport interface ModalsContextValue {\n open?: (options: OpenOptions) => ModalId\n drawer?: (options: ModalOptions) => ModalId\n alert?: (options: ModalOptions) => ModalId\n confirm?: (options: ModalOptions) => ModalId\n close?: (id: ModalId) => void\n closeAll?: () => void\n}\n\nexport const ModalsContext = React.createContext<ModalsContextValue>({})\n\ninterface ModalsProviderProps {\n children: React.ReactNode\n modals?: Record<string, React.FC<any>>\n}\n\nexport type ModalId = string | number\n\ninterface ModalOptions\n extends Omit<\n (ModalProps & DrawerProps & ConfirmDialogProps) & {\n body?: React.ReactNode\n },\n 'onClose' | 'isOpen' | 'children'\n > {\n onClose?: (args: { force?: boolean }) => Promise<boolean | undefined> | void\n children?: React.ReactNode\n}\n\nexport interface OpenOptions extends ModalOptions {\n type?: ModalTypes | string\n scope?: ModalScopes\n}\n\nexport type ModalScopes = 'modal' | 'alert'\n\nexport type ModalTypes = 'modal' | 'drawer' | 'alert' | 'confirm'\n\nexport interface ModalConfig {\n /**\n * The modal id, autogenerated when not set.\n * Can be used to close modals.\n */\n id?: ModalId | null\n /**\n * The modal props\n */\n props?: ModalOptions | null\n /**\n * The modal scope\n * Modals can only have one level per scope.\n * The default scopes are 'modal' and 'alert', alerts can be openend above modals.\n */\n scope?: ModalScopes | string\n /**\n * The modal type to open.\n * Build in types are 'modal', 'drawer', 'alert', 'confirm'\n *\n * Custom types can be configured using the `modals` prop of `ModalProvider`\n */\n type?: ModalTypes | string\n}\n\nconst initialModalState: ModalConfig = {\n id: null,\n props: null,\n type: 'modal',\n}\n\nconst defaultModals = {\n alert: ConfirmDialog,\n confirm: ConfirmDialog,\n drawer: Drawer,\n modal: Modal,\n}\n\nexport function ModalsProvider({ children, modals }: ModalsProviderProps) {\n // Note that updating the Set doesn't trigger a re-render,\n // use in conjuction with setActiveModals\n const _instances = React.useMemo(() => new Set<ModalConfig>(), [])\n\n const [activeModals, setActiveModals] = React.useState<\n Record<string, ModalConfig>\n >({\n modal: initialModalState,\n })\n\n const getModalComponent = React.useMemo(() => {\n const _modals = {\n ...defaultModals,\n ...modals,\n }\n\n return (type = 'modal') => {\n const component = _modals[type] || _modals.modal\n\n return component\n }\n }, [modals])\n\n const setActiveModal = (modal: ModalConfig, scope?: string) => {\n if (!scope) {\n return setActiveModals({\n modal,\n })\n }\n setActiveModals((prevState) => ({\n ...prevState,\n [scope]: modal,\n }))\n }\n\n const open = (options: OpenOptions): ModalId => {\n const {\n id = _instances.size + 1,\n type = 'modal',\n scope = 'modal',\n ...props\n } = options\n\n const modal: ModalConfig = {\n id,\n props: {\n ...props,\n children: props.body || props.children,\n },\n type,\n scope,\n }\n\n _instances.add(modal)\n setActiveModal(modal, scope)\n\n return id\n }\n\n const drawer = (options: ModalOptions): ModalId => {\n return open({\n ...options,\n type: 'drawer',\n })\n }\n\n const alert = (options: ModalOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'alert',\n cancelProps: {\n display: 'none',\n },\n confirmProps: {\n label: 'OK',\n },\n leastDestructiveFocus: 'confirm',\n })\n }\n\n const confirm = (options: ModalOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'confirm',\n })\n }\n\n const close = async (id?: ModalId | null, force?: boolean) => {\n const modals = [..._instances]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n if (!modal) {\n return\n }\n\n const shouldClose = await modal.props?.onClose?.({ force })\n if (shouldClose === false) {\n return\n }\n\n _instances.delete(modal)\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n setActiveModal(\n scoped[scoped.length - 2] || {\n id: null,\n props: null,\n type: modal.type, // Keep type same as last modal type to make sure the animation isn't interrupted\n },\n modal.scope\n )\n }\n\n const closeAll = () => {\n _instances.forEach((modal) => modal.props?.onClose?.({ force: true }))\n _instances.clear()\n\n setActiveModal(initialModalState)\n }\n\n const context = {\n open,\n drawer,\n alert,\n confirm,\n close,\n closeAll,\n }\n\n const content = Object.entries(activeModals).map(([scope, config]) => {\n const Component = getModalComponent(config.type)\n\n const { title, children, ...props } = config.props || {}\n\n return (\n <Component\n key={scope}\n title={title}\n children={children}\n {...props}\n isOpen={!!(config.id && _instances.size)}\n onClose={() => close(config.id)}\n />\n )\n })\n\n return (\n <ModalsContext.Provider value={context}>\n {content}\n {children}\n </ModalsContext.Provider>\n )\n}\n\nexport const useModalsContext = (): ModalsContextValue =>\n React.useContext(ModalsContext)\n\nexport const useModals = () => {\n return useModalsContext()\n}\n"],"names":["ConfirmDialog","props","title","cancelLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","closeOnConfirm","leastDestructiveFocus","onClose","onCancel","onConfirm","children","rest","cancelRef","React","useRef","confirmRef","AlertDialog","leastDestructiveRef","AlertDialogOverlay","AlertDialogContent","AlertDialogHeader","AlertDialogBody","AlertDialogFooter","ButtonGroup","Button","ref","onClick","BaseDrawer","hideCloseButton","hideOverlay","ChakraDrawer","DrawerOverlay","DrawerContent","DrawerHeader","DrawerCloseButton","Drawer","footer","DrawerBody","DrawerFooter","BaseModal","ChakraModal","ModalOverlay","ModalContent","ModalHeader","ModalCloseButton","Modal","ModalBody","ModalFooter","ModalsContext","createContext","initialModalState","id","type","defaultModals","alert","confirm","drawer","modal","ModalsProvider","modals","_instances","useMemo","Set","activeModals","setActiveModals","useState","getModalComponent","_modals","setActiveModal","scope","prevState","open","options","size","body","add","close","async","force","filter","_modal$props","delete","scoped","length","context","display","label","closeAll","forEach","_modal$props2","clear","content","Object","entries","map","config","Component","key","Provider","value","useModalsContext","useContext","useModals"],"mappings":"wgCAsEaA,EAA+CC,IAC1D,MAAMC,MACJA,EADIC,YAEJA,EAAc,SAFVC,aAGJA,EAAe,UAHXC,YAIJA,EAJIC,aAKJA,EALIC,iBAMJA,EANIC,OAOJA,EAPIC,cAQJA,GAAgB,EARZC,eASJA,GAAiB,EATbC,sBAUJA,EAAwB,SAVpBC,QAWJA,EAXIC,SAYJA,EAZIC,UAaJA,EAbIC,SAcJA,GAEEd,EADCe,IACDf,KAEEgB,EAAYC,EAAMC,OAAO,MACzBC,EAAaF,EAAMC,OAAO,mBAEhC,OACED,gBAACG,KACCb,OAAQA,EACRI,QAASA,GACLI,GACJM,oBAC4B,WAA1BX,EAAqCM,EAAYG,iBAGnDF,gBAACK,oBACCL,gBAACM,oBACCN,gBAACO,OAAmBvB,gBAEpBgB,gBAACQ,OAAiBX,gBAElBG,gBAACS,oBACCT,gBAACU,EAAgBrB,eACfW,gBAACW,KACCC,IAAKb,GACDZ,GACJ0B,QAAS,WACPlB,GAAAA,IAEAJ,GAAiBG,8BAKrBM,gBAACW,KACCC,IAAKV,GACDd,GACJyB,QAAS,WACPjB,GAAAA,IAEAJ,GAAkBE,0HCjGvBoB,EAAyC/B,IACpD,MAAMC,MACJA,EADIa,SAEJA,EAFIP,OAGJA,EAHII,QAIJA,EAJIqB,gBAKJA,EALIC,YAMJA,GAEEjC,EADCe,IACDf,kBACJ,OACEiB,gBAACiB,KAAa3B,OAAQA,EAAQI,QAASA,GAAaI,IAChDkB,gBAAehB,gBAACkB,qBAClBlB,gBAACmB,oBACCnB,gBAACoB,OAAcpC,IACb+B,gBAAmBf,gBAACqB,QACrBxB,KAaIyB,EAAiCvC,IAC5C,MAAMwC,OAAEA,EAAF1B,SAAUA,GAAsBd,EAATe,IAASf,kBACtC,OACEiB,gBAAC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5C,KAAMS,EAAWa,MACnClE,QAAS,IAAMqE,EAAMmB,EAAO5C,sBAKlC,OACEtC,gBAACmC,EAAckD,UAASC,MAAOf,GAC5BO,EACAjF,GAKM0F,MAAAA,EAAmB,IAC9BvF,EAAMwF,WAAWrD,GAENsD,EAAY,IAChBF"}
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/dialog.tsx","../src/drawer.tsx","../src/modal.tsx","../src/menu.tsx","../src/form.tsx","../src/provider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n AlertDialog,\n AlertDialogBody,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogContent,\n AlertDialogOverlay,\n AlertDialogProps,\n} from '@chakra-ui/react'\n\nimport {\n ButtonGroup,\n ButtonGroupProps,\n Button,\n ButtonProps,\n} from '@saas-ui/button'\n\nexport interface ConfirmDialogProps\n extends Omit<AlertDialogProps, 'leastDestructiveRef'> {\n /**\n * The dialog title\n */\n title?: React.ReactNode\n /**\n * The cancel button label\n */\n cancelLabel?: React.ReactNode\n /**\n * The confirm button label\n */\n confirmLabel?: React.ReactNode\n /**\n * The cancel button props\n */\n cancelProps?: ButtonProps\n /**\n * The confirm button props\n */\n confirmProps?: ButtonProps\n /**\n * The button group props\n */\n buttonGroupProps?: ButtonGroupProps\n /**\n * Close the dialog on cancel\n * @default true\n */\n closeOnCancel?: boolean\n /**\n * Close the dialog on confirm\n * @default true\n */\n closeOnConfirm?: boolean\n /**\n * Defines which button gets initial focus\n * https://www.w3.org/TR/wai-aria-practices/#alertdialog\n */\n leastDestructiveFocus?: 'cancel' | 'confirm'\n /**\n * Function that's called when cancel is clicked\n */\n onCancel?: () => void\n /**\n * Function that's called when confirm is clicked\n */\n onConfirm?: () => void\n}\n\nexport const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {\n const {\n title,\n cancelLabel = 'Cancel',\n confirmLabel = 'Confirm',\n cancelProps,\n confirmProps,\n buttonGroupProps,\n isOpen,\n closeOnCancel = true,\n closeOnConfirm = true,\n leastDestructiveFocus = 'cancel',\n onClose,\n onCancel,\n onConfirm,\n children,\n ...rest\n } = props\n\n const cancelRef = React.useRef(null)\n const confirmRef = React.useRef(null)\n\n return (\n <AlertDialog\n isOpen={isOpen}\n onClose={onClose}\n {...rest}\n leastDestructiveRef={\n leastDestructiveFocus === 'cancel' ? cancelRef : confirmRef\n }\n >\n <AlertDialogOverlay>\n <AlertDialogContent>\n <AlertDialogHeader>{title}</AlertDialogHeader>\n\n <AlertDialogBody>{children}</AlertDialogBody>\n\n <AlertDialogFooter>\n <ButtonGroup {...buttonGroupProps}>\n <Button\n ref={cancelRef}\n {...cancelProps}\n onClick={() => {\n onCancel?.()\n\n closeOnCancel && onClose()\n }}\n >\n Cancel\n </Button>\n <Button\n ref={confirmRef}\n {...confirmProps}\n onClick={() => {\n onConfirm?.()\n\n closeOnConfirm && onClose()\n }}\n >\n Confirm\n </Button>\n </ButtonGroup>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialogOverlay>\n </AlertDialog>\n )\n}\n","import * as React from 'react'\n\nimport {\n Drawer as ChakraDrawer,\n DrawerOverlay,\n DrawerContent,\n DrawerHeader,\n DrawerFooter,\n DrawerBody,\n DrawerCloseButton,\n DrawerProps as ChakraDrawerProps,\n} from '@chakra-ui/react'\n\nexport interface BaseDrawerProps extends Omit<ChakraDrawerProps, 'children'> {\n /**\n * The drawer title\n */\n title: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overflow\n */\n hideOverlay?: boolean\n children?: React.ReactNode\n}\n\nexport const BaseDrawer: React.FC<BaseDrawerProps> = (props) => {\n const {\n title,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <DrawerOverlay />}\n <DrawerContent>\n <DrawerHeader>{title}</DrawerHeader>\n {!hideCloseButton && <DrawerCloseButton />}\n {children}\n </DrawerContent>\n </ChakraDrawer>\n )\n}\n\nexport interface DrawerProps extends BaseDrawerProps {\n /**\n * Drawer footer content, wrapped with `DrawerFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Drawer: React.FC<DrawerProps> = (props) => {\n const { footer, children, ...rest } = props\n return (\n <BaseDrawer {...rest}>\n <DrawerBody>{children}</DrawerBody>\n\n {footer && <DrawerFooter>{footer}</DrawerFooter>}\n </BaseDrawer>\n )\n}\n","import * as React from 'react'\n\nimport {\n Modal as ChakraModal,\n ModalOverlay,\n ModalContent,\n ModalHeader,\n ModalFooter,\n ModalBody,\n ModalCloseButton,\n ModalProps as ChakraModalProps,\n} from '@chakra-ui/react'\n\nexport interface BaseModalProps extends ChakraModalProps {\n /**\n * The modal title\n */\n title?: React.ReactNode\n /**\n * The modal footer\n */\n footer?: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overlay\n */\n hideOverlay?: boolean\n}\n\nexport const BaseModal: React.FC<BaseModalProps> = (props) => {\n const {\n title,\n footer,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <ModalOverlay />}\n <ModalContent>\n {title && <ModalHeader>{title}</ModalHeader>}\n {!hideCloseButton && <ModalCloseButton />}\n {children}\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </ModalContent>\n </ChakraModal>\n )\n}\n\nexport const Modal: React.FC<BaseModalProps> = (props) => {\n const { children, footer, ...rest } = props\n return (\n <BaseModal {...rest}>\n <ModalBody>{children}</ModalBody>\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport {\n ModalFooter,\n MenuDescendantsProvider,\n MenuProvider,\n MenuListProps,\n useMenu,\n useMenuList,\n chakra,\n StylesProvider,\n useMultiStyleConfig,\n useTheme,\n useStyles,\n forwardRef,\n} from '@chakra-ui/react'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nexport interface MenuDialogProps extends BaseModalProps {\n /**\n * The modal footer, wrapped with `ModalFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const MenuDialog: React.FC<MenuDialogProps> = (props) => {\n const { children, footer, isOpen, onClose, ...rest } = props\n\n const styles = useMultiStyleConfig('Menu', props)\n const { direction } = useTheme()\n const { descendants, ...ctx } = useMenu({\n onClose,\n autoSelect: true,\n defaultIsOpen: true,\n closeOnBlur: false,\n direction,\n })\n const context = React.useMemo(() => ctx, [ctx])\n\n React.useEffect(() => {\n ctx.openAndFocusFirstItem()\n }, [props.isOpen])\n\n return (\n <BaseModal\n isOpen={isOpen}\n onClose={onClose}\n initialFocusRef={ctx.menuRef}\n {...rest}\n >\n <MenuDescendantsProvider value={descendants}>\n <MenuProvider value={context}>\n <StylesProvider value={styles}>{children}</StylesProvider>\n </MenuProvider>\n </MenuDescendantsProvider>\n\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </BaseModal>\n )\n}\n\nMenuDialog.defaultProps = {\n variant: 'dialog',\n}\n\nexport const MenuDialogList = forwardRef<MenuListProps, 'div'>((props, ref) => {\n const { rootProps, ...rest } = props\n\n const ownProps = useMenuList(rest, ref) as any\n\n const styles = useStyles()\n\n return (\n <chakra.div\n {...ownProps}\n __css={{\n outline: 0,\n maxHeight: '80vh', // can override this in theme\n overflowY: 'auto', // can override this in theme\n ...styles.list,\n boxShadow: 'none',\n border: 0,\n }}\n />\n )\n})\n","import * as React from 'react'\n\nimport { ModalBody, ModalFooter } from '@chakra-ui/react'\n\nimport { Form, Fields, SubmitButton, FormProps } from '@saas-ui/forms'\nimport { Button } from '@saas-ui/button'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nexport interface FormDialogProps\n extends Omit<BaseModalProps, 'children'>,\n Pick<\n FormProps,\n | 'schema'\n | 'defaultValues'\n | 'onSubmit'\n | 'resolver'\n | 'mode'\n | 'reValidateMode'\n | 'shouldFocusError'\n | 'shouldUnregister'\n | 'shouldUseNativeValidation'\n | 'criteriaMode'\n | 'delayError'\n > {\n /**\n * The modal footer, will be wrapped with `ModalFooter`.\n * Defaults to a cancel and submit button.\n */\n footer?: React.ReactNode\n /**\n * The cancel button label\n * @default \"Cancel\"\n */\n cancelLabel?: React.ReactNode\n /**\n * The submit button label\n * @default \"Submit\"\n */\n submitLabel?: React.ReactNode\n /**\n * If no children are passed, this will auto render fields based on the supplied schema.\n */\n children?: React.ReactNode\n}\n\nexport const FormDialog: React.FC<FormDialogProps> = (props) => {\n const {\n children,\n schema,\n defaultValues,\n onSubmit,\n reValidateMode,\n shouldFocusError = true,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n cancelLabel,\n submitLabel,\n footer,\n isOpen,\n onClose,\n ...rest\n } = props\n\n const formProps = {\n schema,\n defaultValues,\n onSubmit,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n const initialRef = React.useRef<HTMLButtonElement | null>(null)\n\n return (\n <BaseModal\n isOpen={isOpen}\n onClose={onClose}\n initialFocusRef={initialRef}\n {...rest}\n >\n <Form {...formProps}>\n <ModalBody>{children || <Fields schema={schema} />}</ModalBody>\n\n {footer || (\n <ModalFooter>\n <Button variant=\"ghost\" mr={3} onClick={onClose}>\n {cancelLabel || 'Cancel'}\n </Button>\n <SubmitButton ref={initialRef}>\n {submitLabel || 'Submit'}\n </SubmitButton>\n </ModalFooter>\n )}\n </Form>\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport { Modal, BaseModalProps } from './modal'\nimport { Drawer, DrawerProps } from './drawer'\nimport { ConfirmDialog, ConfirmDialogProps } from './dialog'\nimport { MenuDialog, MenuDialogProps } from './menu'\nimport { FormDialog } from './form'\n\nexport interface ModalsContextValue {\n open?: (options: OpenOptions) => ModalId\n drawer?: (options: ModalOptions) => ModalId\n alert?: (options: ModalOptions) => ModalId\n confirm?: (options: ModalOptions) => ModalId\n menu?: (options: ModalOptions) => ModalId\n form?: (options: ModalOptions) => ModalId\n close?: (id: ModalId) => void\n closeAll?: () => void\n}\n\nexport const ModalsContext = React.createContext<ModalsContextValue>({})\n\ninterface ModalsProviderProps {\n children: React.ReactNode\n modals?: Record<string, React.FC<any>>\n}\n\nexport type ModalId = string | number\n\ninterface ModalOptions\n extends Omit<\n (BaseModalProps & DrawerProps & ConfirmDialogProps) & {\n body?: React.ReactNode\n },\n 'onClose' | 'isOpen' | 'children'\n > {\n onClose?: (args: { force?: boolean }) => Promise<boolean | undefined> | void\n children?: React.ReactNode\n}\n\nexport interface OpenOptions extends ModalOptions {\n type?: ModalTypes | string\n scope?: ModalScopes\n}\n\nexport type ModalScopes = 'modal' | 'alert'\n\nexport type ModalTypes = 'modal' | 'drawer' | 'alert' | 'confirm' | 'menu'\n\nexport interface ModalConfig {\n /**\n * The modal id, autogenerated when not set.\n * Can be used to close modals.\n */\n id?: ModalId | null\n /**\n * The modal props\n */\n props?: ModalOptions | null\n /**\n * The modal scope\n * Modals can only have one level per scope.\n * The default scopes are 'modal' and 'alert', alerts can be openend above modals.\n */\n scope?: ModalScopes | string\n /**\n * The modal type to open.\n * Build in types are 'modal', 'drawer', 'alert', 'confirm'\n *\n * Custom types can be configured using the `modals` prop of `ModalProvider`\n */\n type?: ModalTypes | string\n}\n\nconst initialModalState: ModalConfig = {\n id: null,\n props: null,\n type: 'modal',\n}\n\nconst defaultModals = {\n alert: ConfirmDialog,\n confirm: ConfirmDialog,\n drawer: Drawer,\n modal: Modal,\n menu: MenuDialog,\n form: FormDialog,\n}\n\nexport function ModalsProvider({ children, modals }: ModalsProviderProps) {\n // Note that updating the Set doesn't trigger a re-render,\n // use in conjuction with setActiveModals\n const _instances = React.useMemo(() => new Set<ModalConfig>(), [])\n\n const [activeModals, setActiveModals] = React.useState<\n Record<string, ModalConfig>\n >({\n modal: initialModalState,\n })\n\n const getModalComponent = React.useMemo(() => {\n const _modals = {\n ...defaultModals,\n ...modals,\n }\n\n return (type = 'modal') => {\n const component = _modals[type] || _modals.modal\n\n return component\n }\n }, [modals])\n\n const setActiveModal = (modal: ModalConfig, scope?: string) => {\n if (!scope) {\n return setActiveModals({\n modal,\n })\n }\n setActiveModals((prevState) => ({\n ...prevState,\n [scope]: modal,\n }))\n }\n\n const open = (options: OpenOptions): ModalId => {\n const {\n id = _instances.size + 1,\n type = 'modal',\n scope = 'modal',\n ...props\n } = options\n\n const modal: ModalConfig = {\n id,\n props: {\n ...props,\n children: props.body || props.children,\n },\n type,\n scope,\n }\n\n _instances.add(modal)\n setActiveModal(modal, scope)\n\n return id\n }\n\n const drawer = (options: ModalOptions): ModalId => {\n return open({\n ...options,\n type: 'drawer',\n })\n }\n\n const alert = (options: ModalOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'alert',\n cancelProps: {\n display: 'none',\n },\n confirmProps: {\n label: 'OK',\n },\n leastDestructiveFocus: 'confirm',\n })\n }\n\n const confirm = (options: ModalOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'confirm',\n })\n }\n\n const menu = (options: ModalOptions): ModalId => {\n return open({\n ...options,\n type: 'menu',\n })\n }\n\n const form = (options: ModalOptions): ModalId => {\n return open({\n ...options,\n type: 'form',\n })\n }\n\n const close = async (id?: ModalId | null, force?: boolean) => {\n const modals = [..._instances]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n if (!modal) {\n return\n }\n\n const shouldClose = await modal.props?.onClose?.({ force })\n if (shouldClose === false) {\n return\n }\n\n _instances.delete(modal)\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n setActiveModal(\n scoped[scoped.length - 2] || {\n id: null,\n props: null,\n type: modal.type, // Keep type same as last modal type to make sure the animation isn't interrupted\n },\n modal.scope\n )\n }\n\n const closeAll = () => {\n _instances.forEach((modal) => modal.props?.onClose?.({ force: true }))\n _instances.clear()\n\n setActiveModal(initialModalState)\n }\n\n const context = {\n open,\n drawer,\n alert,\n confirm,\n menu,\n form,\n close,\n closeAll,\n }\n\n const content = Object.entries(activeModals).map(([scope, config]) => {\n const Component = getModalComponent(config.type)\n\n const { title, children, ...props } = config.props || {}\n\n return (\n <Component\n key={scope}\n title={title}\n children={children}\n {...props}\n isOpen={!!(config.id && _instances.size)}\n onClose={() => close(config.id)}\n />\n )\n })\n\n return (\n <ModalsContext.Provider value={context}>\n {content}\n {children}\n </ModalsContext.Provider>\n )\n}\n\nexport const useModalsContext = (): ModalsContextValue =>\n React.useContext(ModalsContext)\n\nexport const useModals = () => {\n return useModalsContext()\n}\n"],"names":["ConfirmDialog","props","title","cancelLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","closeOnCancel","closeOnConfirm","leastDestructiveFocus","onClose","onCancel","onConfirm","children","rest","cancelRef","React","useRef","confirmRef","AlertDialog","leastDestructiveRef","AlertDialogOverlay","AlertDialogContent","AlertDialogHeader","AlertDialogBody","AlertDialogFooter","ButtonGroup","Button","ref","onClick","BaseDrawer","hideCloseButton","hideOverlay","ChakraDrawer","DrawerOverlay","DrawerContent","DrawerHeader","DrawerCloseButton","Drawer","footer","DrawerBody","DrawerFooter","BaseModal","ChakraModal","ModalOverlay","ModalContent","ModalHeader","ModalCloseButton","ModalFooter","Modal","ModalBody","MenuDialog","styles","useMultiStyleConfig","direction","useTheme","useMenu","autoSelect","defaultIsOpen","closeOnBlur","descendants","ctx","context","useMemo","useEffect","openAndFocusFirstItem","initialFocusRef","menuRef","MenuDescendantsProvider","value","MenuProvider","StylesProvider","defaultProps","variant","MenuDialogList","forwardRef","ownProps","useMenuList","useStyles","chakra","div","__css","outline","maxHeight","overflowY","list","boxShadow","border","FormDialog","schema","defaultValues","onSubmit","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","submitLabel","formProps","initialRef","Form","Fields","mr","SubmitButton","ModalsContext","createContext","initialModalState","id","type","defaultModals","alert","confirm","drawer","modal","menu","form","ModalsProvider","modals","_instances","Set","activeModals","setActiveModals","useState","getModalComponent","_modals","setActiveModal","scope","prevState","open","options","size","body","add","close","async","force","filter","_modal$props","delete","scoped","length","display","label","closeAll","forEach","_modal$props2","clear","content","Object","entries","map","config","Component","key","Provider","useModalsContext","useContext","useModals"],"mappings":"+vCAsEaA,EAA+CC,IAC1D,MAAMC,MACJA,EADIC,YAEJA,EAAc,SAFVC,aAGJA,EAAe,UAHXC,YAIJA,EAJIC,aAKJA,EALIC,iBAMJA,EANIC,OAOJA,EAPIC,cAQJA,GAAgB,EARZC,eASJA,GAAiB,EATbC,sBAUJA,EAAwB,SAVpBC,QAWJA,EAXIC,SAYJA,EAZIC,UAaJA,EAbIC,SAcJA,GAEEd,EADCe,IACDf,KAEEgB,EAAYC,EAAMC,OAAO,MACzBC,EAAaF,EAAMC,OAAO,mBAEhC,OACED,gBAACG,KACCb,OAAQA,EACRI,QAASA,GACLI,GACJM,oBAC4B,WAA1BX,EAAqCM,EAAYG,iBAGnDF,gBAACK,oBACCL,gBAACM,oBACCN,gBAACO,OAAmBvB,gBAEpBgB,gBAACQ,OAAiBX,gBAElBG,gBAACS,oBACCT,gBAACU,EAAgBrB,eACfW,gBAACW,KACCC,IAAKb,GACDZ,GACJ0B,QAAS,WACPlB,GAAAA,IAEAJ,GAAiBG,8BAKrBM,gBAACW,KACCC,IAAKV,GACDd,GACJyB,QAAS,WACPjB,GAAAA,IAEAJ,GAAkBE,0HCjGvBoB,EAAyC/B,IACpD,MAAMC,MACJA,EADIa,SAEJA,EAFIP,OAGJA,EAHII,QAIJA,EAJIqB,gBAKJA,EALIC,YAMJA,GAEEjC,EADCe,IACDf,kBACJ,OACEiB,gBAACiB,KAAa3B,OAAQA,EAAQI,QAASA,GAAaI,IAChDkB,gBAAehB,gBAACkB,qBAClBlB,gBAACmB,oBACCnB,gBAACoB,OAAcpC,IACb+B,gBAAmBf,gBAACqB,QACrBxB,KAaIyB,EAAiCvC,IAC5C,MAAMwC,OAAEA,EAAF1B,SAAUA,GAAsBd,EAATe,IAASf,kBACtC,OACEiB,gBAACc,EAAehB,eACd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lB,KAAM,aAyDRM,KArDYe,GACLD,OACFC,GACHrB,KAAM,UAmDRO,KA/CYc,GACLD,OACFC,GACHrB,KAAM,UA6CRyB,MAAAA,EACAU,SAfe,KACfzB,EAAW0B,QAAS/B,0BAAUA,EAAMnH,cAANmJ,EAAaxI,eAAbwI,EAAaxI,QAAU,CAAE8H,OAAO,MAC9DjB,EAAW4B,QAEXrB,EAAenB,MAcXyC,EAAUC,OAAOC,QAAQ7B,GAAc8B,IAAI,EAAExB,EAAOyB,MACxD,MAAMC,EAAY7B,EAAkB4B,EAAO3C,QAEL2C,EAAOzJ,OAAS,IAAhDC,MAAEA,EAAFa,SAASA,KAAad,uBAE5B,OACEiB,gBAACyI,KACCC,IAAK3B,EACL/H,MAAOA,EACPa,SAAUA,GACNd,GACJO,UAAWkJ,EAAO5C,KAAMW,EAAWY,MACnCzH,QAAS,IAAM4H,EAAMkB,EAAO5C,sBAKlC,OACE5F,gBAACyF,GAAckD,UAAStF,MAAOP,GAC5BsF,EACAvI,GAKM+I,MAAAA,GAAmB,IAC9B5I,EAAM6I,WAAWpD,IAENqD,GAAY,IAChBF"}
|
package/dist/menu.d.ts
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { MenuListProps } from '@chakra-ui/react';
|
3
|
+
import { BaseModalProps } from './modal';
|
4
|
+
export interface MenuDialogProps extends BaseModalProps {
|
5
|
+
/**
|
6
|
+
* The modal footer, wrapped with `ModalFooter`
|
7
|
+
*/
|
8
|
+
footer?: React.ReactNode;
|
9
|
+
}
|
10
|
+
export declare const MenuDialog: React.FC<MenuDialogProps>;
|
11
|
+
export declare const MenuDialogList: import("@chakra-ui/react").ComponentWithAs<"div", MenuListProps>;
|
12
|
+
//# sourceMappingURL=menu.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../src/menu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAIL,aAAa,EASd,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAa,cAAc,EAAE,MAAM,SAAS,CAAA;AAEnD,MAAM,WAAW,eAAgB,SAAQ,cAAc;IACrD;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CACzB;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAkChD,CAAA;AAMD,eAAO,MAAM,cAAc,kEAoBzB,CAAA"}
|
package/dist/modal.d.ts
CHANGED
@@ -4,7 +4,11 @@ export interface BaseModalProps extends ChakraModalProps {
|
|
4
4
|
/**
|
5
5
|
* The modal title
|
6
6
|
*/
|
7
|
-
title
|
7
|
+
title?: React.ReactNode;
|
8
|
+
/**
|
9
|
+
* The modal footer
|
10
|
+
*/
|
11
|
+
footer?: React.ReactNode;
|
8
12
|
/**
|
9
13
|
* Hide the close button
|
10
14
|
*/
|
@@ -15,11 +19,5 @@ export interface BaseModalProps extends ChakraModalProps {
|
|
15
19
|
hideOverlay?: boolean;
|
16
20
|
}
|
17
21
|
export declare const BaseModal: React.FC<BaseModalProps>;
|
18
|
-
export
|
19
|
-
/**
|
20
|
-
* The modal footer, wrapped with `ModalFooter`
|
21
|
-
*/
|
22
|
-
footer?: React.ReactNode;
|
23
|
-
}
|
24
|
-
export declare const Modal: React.FC<ModalProps>;
|
22
|
+
export declare const Modal: React.FC<BaseModalProps>;
|
25
23
|
//# sourceMappingURL=modal.d.ts.map
|
package/dist/modal.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/modal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAQL,UAAU,IAAI,gBAAgB,EAC/B,MAAM,kBAAkB,CAAA;AAEzB,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/modal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAQL,UAAU,IAAI,gBAAgB,EAC/B,MAAM,kBAAkB,CAAA;AAEzB,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACxB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAsB9C,CAAA;AAED,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAO1C,CAAA"}
|
package/dist/provider.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import {
|
2
|
+
import { BaseModalProps } from './modal';
|
3
3
|
import { DrawerProps } from './drawer';
|
4
4
|
import { ConfirmDialogProps } from './dialog';
|
5
5
|
export interface ModalsContextValue {
|
@@ -7,6 +7,8 @@ export interface ModalsContextValue {
|
|
7
7
|
drawer?: (options: ModalOptions) => ModalId;
|
8
8
|
alert?: (options: ModalOptions) => ModalId;
|
9
9
|
confirm?: (options: ModalOptions) => ModalId;
|
10
|
+
menu?: (options: ModalOptions) => ModalId;
|
11
|
+
form?: (options: ModalOptions) => ModalId;
|
10
12
|
close?: (id: ModalId) => void;
|
11
13
|
closeAll?: () => void;
|
12
14
|
}
|
@@ -16,7 +18,7 @@ interface ModalsProviderProps {
|
|
16
18
|
modals?: Record<string, React.FC<any>>;
|
17
19
|
}
|
18
20
|
export declare type ModalId = string | number;
|
19
|
-
interface ModalOptions extends Omit<(
|
21
|
+
interface ModalOptions extends Omit<(BaseModalProps & DrawerProps & ConfirmDialogProps) & {
|
20
22
|
body?: React.ReactNode;
|
21
23
|
}, 'onClose' | 'isOpen' | 'children'> {
|
22
24
|
onClose?: (args: {
|
@@ -29,7 +31,7 @@ export interface OpenOptions extends ModalOptions {
|
|
29
31
|
scope?: ModalScopes;
|
30
32
|
}
|
31
33
|
export declare type ModalScopes = 'modal' | 'alert';
|
32
|
-
export declare type ModalTypes = 'modal' | 'drawer' | 'alert' | 'confirm';
|
34
|
+
export declare type ModalTypes = 'modal' | 'drawer' | 'alert' | 'confirm' | 'menu';
|
33
35
|
export interface ModalConfig {
|
34
36
|
/**
|
35
37
|
* The modal id, autogenerated when not set.
|
package/dist/provider.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAS,
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAS,cAAc,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAU,WAAW,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAiB,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAI5D,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAA;IACxC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAA;IAC3C,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAA;IAC1C,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAA;IAC5C,IAAI,CAAC,EAAE,CAA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,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;IAC3B;;;;OAIG;IACH,KAAK,CAAC,EAAE,WAAW,GAAG,MAAM,CAAA;IAC5B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,CAAA;CAC3B;AAiBD,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,mBAAmB,eA4KvE;AAED,eAAO,MAAM,gBAAgB,QAAO,kBACH,CAAA;AAEjC,eAAO,MAAM,SAAS,0BAErB,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@saas-ui/modals",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.3",
|
4
4
|
"description": "A modal manager for Chakra UI",
|
5
5
|
"source": "src/index.ts",
|
6
6
|
"exports": {
|
@@ -22,6 +22,10 @@
|
|
22
22
|
"lint:staged": "lint-staged --allow-empty --config ../../lint-staged.config.js",
|
23
23
|
"typecheck": "tsc --noEmit"
|
24
24
|
},
|
25
|
+
"files": [
|
26
|
+
"dist",
|
27
|
+
"src"
|
28
|
+
],
|
25
29
|
"sideEffects": false,
|
26
30
|
"publishConfig": {
|
27
31
|
"access": "public"
|
@@ -52,7 +56,8 @@
|
|
52
56
|
"url": "https://storybook.saas-ui.dev"
|
53
57
|
},
|
54
58
|
"dependencies": {
|
55
|
-
"@saas-ui/button": "0.2.
|
59
|
+
"@saas-ui/button": "0.2.1",
|
60
|
+
"@saas-ui/forms": "0.2.5"
|
56
61
|
},
|
57
62
|
"peerDependencies": {
|
58
63
|
"@chakra-ui/react": ">=1.8.0",
|
package/src/form.tsx
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
import * as React from 'react'
|
2
|
+
|
3
|
+
import { ModalBody, ModalFooter } from '@chakra-ui/react'
|
4
|
+
|
5
|
+
import { Form, Fields, SubmitButton, FormProps } from '@saas-ui/forms'
|
6
|
+
import { Button } from '@saas-ui/button'
|
7
|
+
|
8
|
+
import { BaseModal, BaseModalProps } from './modal'
|
9
|
+
|
10
|
+
export interface FormDialogProps
|
11
|
+
extends Omit<BaseModalProps, 'children'>,
|
12
|
+
Pick<
|
13
|
+
FormProps,
|
14
|
+
| 'schema'
|
15
|
+
| 'defaultValues'
|
16
|
+
| 'onSubmit'
|
17
|
+
| 'resolver'
|
18
|
+
| 'mode'
|
19
|
+
| 'reValidateMode'
|
20
|
+
| 'shouldFocusError'
|
21
|
+
| 'shouldUnregister'
|
22
|
+
| 'shouldUseNativeValidation'
|
23
|
+
| 'criteriaMode'
|
24
|
+
| 'delayError'
|
25
|
+
> {
|
26
|
+
/**
|
27
|
+
* The modal footer, will be wrapped with `ModalFooter`.
|
28
|
+
* Defaults to a cancel and submit button.
|
29
|
+
*/
|
30
|
+
footer?: React.ReactNode
|
31
|
+
/**
|
32
|
+
* The cancel button label
|
33
|
+
* @default "Cancel"
|
34
|
+
*/
|
35
|
+
cancelLabel?: React.ReactNode
|
36
|
+
/**
|
37
|
+
* The submit button label
|
38
|
+
* @default "Submit"
|
39
|
+
*/
|
40
|
+
submitLabel?: React.ReactNode
|
41
|
+
/**
|
42
|
+
* If no children are passed, this will auto render fields based on the supplied schema.
|
43
|
+
*/
|
44
|
+
children?: React.ReactNode
|
45
|
+
}
|
46
|
+
|
47
|
+
export const FormDialog: React.FC<FormDialogProps> = (props) => {
|
48
|
+
const {
|
49
|
+
children,
|
50
|
+
schema,
|
51
|
+
defaultValues,
|
52
|
+
onSubmit,
|
53
|
+
reValidateMode,
|
54
|
+
shouldFocusError = true,
|
55
|
+
shouldUnregister,
|
56
|
+
shouldUseNativeValidation,
|
57
|
+
criteriaMode,
|
58
|
+
delayError,
|
59
|
+
cancelLabel,
|
60
|
+
submitLabel,
|
61
|
+
footer,
|
62
|
+
isOpen,
|
63
|
+
onClose,
|
64
|
+
...rest
|
65
|
+
} = props
|
66
|
+
|
67
|
+
const formProps = {
|
68
|
+
schema,
|
69
|
+
defaultValues,
|
70
|
+
onSubmit,
|
71
|
+
reValidateMode,
|
72
|
+
shouldFocusError,
|
73
|
+
shouldUnregister,
|
74
|
+
shouldUseNativeValidation,
|
75
|
+
criteriaMode,
|
76
|
+
delayError,
|
77
|
+
}
|
78
|
+
|
79
|
+
const initialRef = React.useRef<HTMLButtonElement | null>(null)
|
80
|
+
|
81
|
+
return (
|
82
|
+
<BaseModal
|
83
|
+
isOpen={isOpen}
|
84
|
+
onClose={onClose}
|
85
|
+
initialFocusRef={initialRef}
|
86
|
+
{...rest}
|
87
|
+
>
|
88
|
+
<Form {...formProps}>
|
89
|
+
<ModalBody>{children || <Fields schema={schema} />}</ModalBody>
|
90
|
+
|
91
|
+
{footer || (
|
92
|
+
<ModalFooter>
|
93
|
+
<Button variant="ghost" mr={3} onClick={onClose}>
|
94
|
+
{cancelLabel || 'Cancel'}
|
95
|
+
</Button>
|
96
|
+
<SubmitButton ref={initialRef}>
|
97
|
+
{submitLabel || 'Submit'}
|
98
|
+
</SubmitButton>
|
99
|
+
</ModalFooter>
|
100
|
+
)}
|
101
|
+
</Form>
|
102
|
+
</BaseModal>
|
103
|
+
)
|
104
|
+
}
|
package/src/index.ts
CHANGED
package/src/menu.tsx
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
import * as React from 'react'
|
2
|
+
|
3
|
+
import {
|
4
|
+
ModalFooter,
|
5
|
+
MenuDescendantsProvider,
|
6
|
+
MenuProvider,
|
7
|
+
MenuListProps,
|
8
|
+
useMenu,
|
9
|
+
useMenuList,
|
10
|
+
chakra,
|
11
|
+
StylesProvider,
|
12
|
+
useMultiStyleConfig,
|
13
|
+
useTheme,
|
14
|
+
useStyles,
|
15
|
+
forwardRef,
|
16
|
+
} from '@chakra-ui/react'
|
17
|
+
|
18
|
+
import { BaseModal, BaseModalProps } from './modal'
|
19
|
+
|
20
|
+
export interface MenuDialogProps extends BaseModalProps {
|
21
|
+
/**
|
22
|
+
* The modal footer, wrapped with `ModalFooter`
|
23
|
+
*/
|
24
|
+
footer?: React.ReactNode
|
25
|
+
}
|
26
|
+
|
27
|
+
export const MenuDialog: React.FC<MenuDialogProps> = (props) => {
|
28
|
+
const { children, footer, isOpen, onClose, ...rest } = props
|
29
|
+
|
30
|
+
const styles = useMultiStyleConfig('Menu', props)
|
31
|
+
const { direction } = useTheme()
|
32
|
+
const { descendants, ...ctx } = useMenu({
|
33
|
+
onClose,
|
34
|
+
autoSelect: true,
|
35
|
+
defaultIsOpen: true,
|
36
|
+
closeOnBlur: false,
|
37
|
+
direction,
|
38
|
+
})
|
39
|
+
const context = React.useMemo(() => ctx, [ctx])
|
40
|
+
|
41
|
+
React.useEffect(() => {
|
42
|
+
ctx.openAndFocusFirstItem()
|
43
|
+
}, [props.isOpen])
|
44
|
+
|
45
|
+
return (
|
46
|
+
<BaseModal
|
47
|
+
isOpen={isOpen}
|
48
|
+
onClose={onClose}
|
49
|
+
initialFocusRef={ctx.menuRef}
|
50
|
+
{...rest}
|
51
|
+
>
|
52
|
+
<MenuDescendantsProvider value={descendants}>
|
53
|
+
<MenuProvider value={context}>
|
54
|
+
<StylesProvider value={styles}>{children}</StylesProvider>
|
55
|
+
</MenuProvider>
|
56
|
+
</MenuDescendantsProvider>
|
57
|
+
|
58
|
+
{footer && <ModalFooter>{footer}</ModalFooter>}
|
59
|
+
</BaseModal>
|
60
|
+
)
|
61
|
+
}
|
62
|
+
|
63
|
+
MenuDialog.defaultProps = {
|
64
|
+
variant: 'dialog',
|
65
|
+
}
|
66
|
+
|
67
|
+
export const MenuDialogList = forwardRef<MenuListProps, 'div'>((props, ref) => {
|
68
|
+
const { rootProps, ...rest } = props
|
69
|
+
|
70
|
+
const ownProps = useMenuList(rest, ref) as any
|
71
|
+
|
72
|
+
const styles = useStyles()
|
73
|
+
|
74
|
+
return (
|
75
|
+
<chakra.div
|
76
|
+
{...ownProps}
|
77
|
+
__css={{
|
78
|
+
outline: 0,
|
79
|
+
maxHeight: '80vh', // can override this in theme
|
80
|
+
overflowY: 'auto', // can override this in theme
|
81
|
+
...styles.list,
|
82
|
+
boxShadow: 'none',
|
83
|
+
border: 0,
|
84
|
+
}}
|
85
|
+
/>
|
86
|
+
)
|
87
|
+
})
|
package/src/modal.tsx
CHANGED
@@ -15,7 +15,11 @@ export interface BaseModalProps extends ChakraModalProps {
|
|
15
15
|
/**
|
16
16
|
* The modal title
|
17
17
|
*/
|
18
|
-
title
|
18
|
+
title?: React.ReactNode
|
19
|
+
/**
|
20
|
+
* The modal footer
|
21
|
+
*/
|
22
|
+
footer?: React.ReactNode
|
19
23
|
/**
|
20
24
|
* Hide the close button
|
21
25
|
*/
|
@@ -29,6 +33,7 @@ export interface BaseModalProps extends ChakraModalProps {
|
|
29
33
|
export const BaseModal: React.FC<BaseModalProps> = (props) => {
|
30
34
|
const {
|
31
35
|
title,
|
36
|
+
footer,
|
32
37
|
children,
|
33
38
|
isOpen,
|
34
39
|
onClose,
|
@@ -40,28 +45,20 @@ export const BaseModal: React.FC<BaseModalProps> = (props) => {
|
|
40
45
|
<ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>
|
41
46
|
{!hideOverlay && <ModalOverlay />}
|
42
47
|
<ModalContent>
|
43
|
-
<ModalHeader>{title}</ModalHeader>
|
48
|
+
{title && <ModalHeader>{title}</ModalHeader>}
|
44
49
|
{!hideCloseButton && <ModalCloseButton />}
|
45
50
|
{children}
|
51
|
+
{footer && <ModalFooter>{footer}</ModalFooter>}
|
46
52
|
</ModalContent>
|
47
53
|
</ChakraModal>
|
48
54
|
)
|
49
55
|
}
|
50
56
|
|
51
|
-
export
|
52
|
-
/**
|
53
|
-
* The modal footer, wrapped with `ModalFooter`
|
54
|
-
*/
|
55
|
-
footer?: React.ReactNode
|
56
|
-
}
|
57
|
-
|
58
|
-
export const Modal: React.FC<ModalProps> = (props) => {
|
57
|
+
export const Modal: React.FC<BaseModalProps> = (props) => {
|
59
58
|
const { children, footer, ...rest } = props
|
60
59
|
return (
|
61
60
|
<BaseModal {...rest}>
|
62
61
|
<ModalBody>{children}</ModalBody>
|
63
|
-
|
64
|
-
{footer && <ModalFooter>{footer}</ModalFooter>}
|
65
62
|
</BaseModal>
|
66
63
|
)
|
67
64
|
}
|
package/src/provider.tsx
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
import * as React from 'react'
|
2
2
|
|
3
|
-
import { Modal,
|
3
|
+
import { Modal, BaseModalProps } from './modal'
|
4
4
|
import { Drawer, DrawerProps } from './drawer'
|
5
5
|
import { ConfirmDialog, ConfirmDialogProps } from './dialog'
|
6
|
+
import { MenuDialog, MenuDialogProps } from './menu'
|
7
|
+
import { FormDialog } from './form'
|
6
8
|
|
7
9
|
export interface ModalsContextValue {
|
8
10
|
open?: (options: OpenOptions) => ModalId
|
9
11
|
drawer?: (options: ModalOptions) => ModalId
|
10
12
|
alert?: (options: ModalOptions) => ModalId
|
11
13
|
confirm?: (options: ModalOptions) => ModalId
|
14
|
+
menu?: (options: ModalOptions) => ModalId
|
15
|
+
form?: (options: ModalOptions) => ModalId
|
12
16
|
close?: (id: ModalId) => void
|
13
17
|
closeAll?: () => void
|
14
18
|
}
|
@@ -24,7 +28,7 @@ export type ModalId = string | number
|
|
24
28
|
|
25
29
|
interface ModalOptions
|
26
30
|
extends Omit<
|
27
|
-
(
|
31
|
+
(BaseModalProps & DrawerProps & ConfirmDialogProps) & {
|
28
32
|
body?: React.ReactNode
|
29
33
|
},
|
30
34
|
'onClose' | 'isOpen' | 'children'
|
@@ -40,7 +44,7 @@ export interface OpenOptions extends ModalOptions {
|
|
40
44
|
|
41
45
|
export type ModalScopes = 'modal' | 'alert'
|
42
46
|
|
43
|
-
export type ModalTypes = 'modal' | 'drawer' | 'alert' | 'confirm'
|
47
|
+
export type ModalTypes = 'modal' | 'drawer' | 'alert' | 'confirm' | 'menu'
|
44
48
|
|
45
49
|
export interface ModalConfig {
|
46
50
|
/**
|
@@ -78,6 +82,8 @@ const defaultModals = {
|
|
78
82
|
confirm: ConfirmDialog,
|
79
83
|
drawer: Drawer,
|
80
84
|
modal: Modal,
|
85
|
+
menu: MenuDialog,
|
86
|
+
form: FormDialog,
|
81
87
|
}
|
82
88
|
|
83
89
|
export function ModalsProvider({ children, modals }: ModalsProviderProps) {
|
@@ -170,6 +176,20 @@ export function ModalsProvider({ children, modals }: ModalsProviderProps) {
|
|
170
176
|
})
|
171
177
|
}
|
172
178
|
|
179
|
+
const menu = (options: ModalOptions): ModalId => {
|
180
|
+
return open({
|
181
|
+
...options,
|
182
|
+
type: 'menu',
|
183
|
+
})
|
184
|
+
}
|
185
|
+
|
186
|
+
const form = (options: ModalOptions): ModalId => {
|
187
|
+
return open({
|
188
|
+
...options,
|
189
|
+
type: 'form',
|
190
|
+
})
|
191
|
+
}
|
192
|
+
|
173
193
|
const close = async (id?: ModalId | null, force?: boolean) => {
|
174
194
|
const modals = [..._instances]
|
175
195
|
const modal = modals.filter((modal) => modal.id === id)[0]
|
@@ -209,6 +229,8 @@ export function ModalsProvider({ children, modals }: ModalsProviderProps) {
|
|
209
229
|
drawer,
|
210
230
|
alert,
|
211
231
|
confirm,
|
232
|
+
menu,
|
233
|
+
form,
|
212
234
|
close,
|
213
235
|
closeAll,
|
214
236
|
}
|
package/.turbo/turbo-build.log
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
[35m@saas-ui/modals:build: [0mcache hit, replaying output [2mc20143510457fd4d[0m
|
2
|
-
[35m@saas-ui/modals:build: [0mBuild "@saas-ui/modals" to dist:
|
3
|
-
[35m@saas-ui/modals:build: [0m 1.82 kB: index.js.gz
|
4
|
-
[35m@saas-ui/modals:build: [0m 1.63 kB: index.js.br
|
5
|
-
[35m@saas-ui/modals:build: [0m 1696 B: index.modern.js.gz
|
6
|
-
[35m@saas-ui/modals:build: [0m 1529 B: index.modern.js.br
|