UNPKG

@react-spectrum/s2

Version:
1 lines 5.86 kB
{"mappings":"ACgFmB;EAAA;;;;EAAA;;;;EAgDQ;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA","sources":["9979cbf3a881af08","packages/@react-spectrum/s2/src/Icon.tsx"],"sourcesContent":["@import \"6b03dceb9b361c08\";\n@import \"4419ac9b4a6c26ae\";\n","/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps} from '@react-types/shared';\nimport {ComponentType, Context, createContext, FunctionComponent, ReactNode, SVGProps, useRef} from 'react';\nimport {ContextValue, SlotProps} from 'react-aria-components';\nimport {mergeStyles} from '../style/runtime';\nimport {SkeletonWrapper, useSkeletonIcon} from './Skeleton';\nimport {style} from '../style' with {type: 'macro'};\nimport {StyleString} from '../style/types';\nimport {UnsafeStyles} from './style-utils' with {type: 'macro'};\nimport {useSpectrumContextProps} from './useSpectrumContextProps';\n\n// Custom list of overrides, excluding width/height/flexGrow/flexShrink/flexBasis\nconst allowedOverrides = [\n 'margin',\n 'marginStart',\n 'marginEnd',\n 'marginTop',\n 'marginBottom',\n 'marginX',\n 'marginY',\n 'justifySelf',\n 'alignSelf',\n 'order',\n 'gridArea',\n 'gridRowStart',\n 'gridRowEnd',\n 'gridColumnStart',\n 'gridColumnEnd',\n 'position',\n 'zIndex',\n 'top',\n 'bottom',\n 'inset',\n 'insetX',\n 'insetY',\n 'insetStart',\n 'insetEnd',\n 'rotate',\n '--iconPrimary',\n 'size'\n] as const;\n\n// Omit --iconPrimary and size from type (they are private).\n// Use the iconStyle() macro to apply them.\ntype AllowedOverrides = Exclude<(typeof allowedOverrides)[number], '--iconPrimary' | 'size'>;\n\nexport interface IconProps extends UnsafeStyles, SlotProps, AriaLabelingProps, DOMProps {\n 'aria-hidden'?: boolean | 'false' | 'true',\n styles?: StyleString<AllowedOverrides>\n}\n\nexport interface IconContextValue extends UnsafeStyles, SlotProps {\n styles?: StyleString,\n render?: (icon: ReactNode) => ReactNode\n}\n\nexport interface IllustrationProps extends UnsafeStyles, SlotProps, AriaLabelingProps, DOMProps {\n 'aria-hidden'?: boolean | 'false' | 'true',\n size?: 'S' | 'M' | 'L',\n styles?: StyleString<AllowedOverrides>\n}\n\nexport interface IllustrationContextValue extends IconContextValue {\n size?: 'S' | 'M' | 'L'\n}\n\nexport const IconContext = createContext<ContextValue<Partial<IconContextValue>, SVGElement>>({});\nexport const IllustrationContext = createContext<ContextValue<Partial<IllustrationContextValue>, SVGElement>>({});\n\nconst iconStyles = style({\n size: 20,\n flexShrink: 0\n}, allowedOverrides);\n\nexport function createIcon(Component: ComponentType<SVGProps<SVGSVGElement>>, context: Context<ContextValue<IconContextValue, SVGElement>> = IconContext): FunctionComponent<IconProps> {\n return (props: IconProps) => {\n let ref = useRef<SVGElement>(null);\n let ctx;\n // TODO: remove this default once we release RAC and use DEFAULT_SLOT.\n [ctx, ref] = useSpectrumContextProps({slot: props.slot || 'icon'} as IconContextValue, ref, context);\n let {render, styles: ctxStyles} = ctx;\n let {\n UNSAFE_className,\n UNSAFE_style,\n slot,\n 'aria-label': ariaLabel,\n 'aria-hidden': ariaHidden,\n styles,\n ...otherProps\n } = props;\n\n if (!ariaHidden) {\n ariaHidden = undefined;\n }\n\n let svg = (\n <SkeletonWrapper>\n <Component\n {...otherProps}\n focusable={false}\n aria-label={ariaLabel}\n aria-hidden={ariaLabel ? (ariaHidden || undefined) : true}\n role=\"img\"\n data-slot={slot}\n className={(UNSAFE_className ?? '') + ' ' + useSkeletonIcon(mergeStyles(iconStyles(null, styles), ctxStyles))}\n style={UNSAFE_style} />\n </SkeletonWrapper>\n );\n\n if (render) {\n return render(svg);\n }\n\n return svg;\n };\n}\n\nconst illustrationStyles = style({\n size: {\n size: {\n S: 48,\n M: 96,\n L: 160\n }\n },\n flexShrink: 0\n}, allowedOverrides);\n\nexport function createIllustration(Component: ComponentType<SVGProps<SVGSVGElement>>): FunctionComponent<IllustrationProps> {\n return (props: IllustrationProps) => {\n let ref = useRef<SVGElement>(null);\n let ctx;\n [ctx, ref] = useSpectrumContextProps({slot: props.slot || 'icon'} as IconContextValue, ref, IllustrationContext);\n let {render, styles: ctxStyles} = ctx;\n let {\n UNSAFE_className,\n UNSAFE_style,\n slot,\n 'aria-label': ariaLabel,\n 'aria-hidden': ariaHidden,\n size = ctx.size || 'M',\n styles,\n ...otherProps\n } = props;\n\n if (!ariaHidden) {\n ariaHidden = undefined;\n }\n\n let svg = (\n <Component\n {...otherProps}\n // @ts-ignore\n size={size}\n focusable={false}\n aria-label={ariaLabel}\n aria-hidden={ariaLabel ? (ariaHidden || undefined) : true}\n role=\"img\"\n data-slot={slot}\n className={(UNSAFE_className ?? '') + ' ' + illustrationStyles({size}, styles) + (ctxStyles || '')}\n style={UNSAFE_style} />\n );\n\n if (render) {\n return render(svg);\n }\n\n return svg;\n };\n}\n"],"names":[],"version":3,"file":"Icon.css.map"}