UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

1 lines 1.29 kB
{"version":3,"file":"show.cjs","names":["result: ReactNode"],"sources":["../../../../src/components/show/show.tsx"],"sourcesContent":["import type { ReactNode } from \"react\"\nimport type { ReactNodeOrFunction } from \"../../utils\"\nimport { isValidElement } from \"react\"\nimport { runIfFn } from \"../../utils\"\n\nexport interface ShowProps<Y> {\n /**\n * The children to render if `when` is `true`\n */\n children: ReactNodeOrFunction<Y>\n /**\n * The fallback content to render if `when` is `false`\n */\n fallback?: ReactNode\n /**\n * If `true`, it'll render the `children` prop\n */\n when?: null | Y\n}\n\n/**\n * `Show` is a component that shows or hides its children based on a condition.\n *\n * @see https://yamada-ui.com/docs/components/show\n */\nexport const Show = <Y,>({\n children,\n fallback,\n when,\n}: ShowProps<Y>): ReactNode => {\n let result: ReactNode\n\n if (!when) {\n result = fallback\n } else {\n result = runIfFn(children, when)\n }\n\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return isValidElement(result) ? result : <>{result}</>\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,MAAa,QAAY,EACvB,UACA,UACA,WAC6B;CAC7B,IAAIA;AAEJ,KAAI,CAAC,KACH,UAAS;KAET,yDAAiB,UAAU,KAAK;AAIlC,kCAAsB,OAAO,GAAG,SAAS,mFAAG,SAAU"}