@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 8.25 kB
Source Map (JSON)
{"version":3,"file":"ActionIcon.cjs","names":["createVarsResolver","getSize","getRadius","polymorphicFactory","useProps","useStyles","UnstyledButton","Transition","Box","Loader","classes","ActionIconGroup","ActionIconGroupSection"],"sources":["../../../src/components/ActionIcon/ActionIcon.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n createVarsResolver,\n getRadius,\n getSize,\n MantineColor,\n MantineGradient,\n MantineRadius,\n MantineSize,\n polymorphicFactory,\n PolymorphicFactory,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { Loader, LoaderProps } from '../Loader';\nimport { Transition } from '../Transition';\nimport { UnstyledButton } from '../UnstyledButton';\nimport {\n ActionIconGroup,\n type ActionIconGroupProps,\n type ActionIconGroupStylesNames,\n type ActionIconGroupCssVariables,\n type ActionIconGroupFactory,\n} from './ActionIconGroup/ActionIconGroup';\nimport {\n ActionIconGroupSection,\n type ActionIconGroupSectionProps,\n type ActionIconGroupSectionStylesNames,\n type ActionIconGroupSectionCssVariables,\n type ActionIconGroupSectionFactory,\n} from './ActionIconGroupSection/ActionIconGroupSection';\nimport classes from './ActionIcon.module.css';\nexport type ActionIconVariant =\n | 'filled'\n | 'light'\n | 'outline'\n | 'transparent'\n | 'white'\n | 'subtle'\n | 'default'\n | 'gradient';\n\nexport type ActionIconStylesNames = 'root' | 'loader' | 'icon';\nexport type ActionIconCssVariables = {\n root:\n | '--ai-radius'\n | '--ai-size'\n | '--ai-bg'\n | '--ai-hover'\n | '--ai-hover-color'\n | '--ai-color'\n | '--ai-bd';\n};\n\nexport interface ActionIconProps extends BoxProps, StylesApiProps<ActionIconFactory> {\n 'data-disabled'?: boolean;\n __staticSelector?: string;\n\n /** If set, `Loader` component is displayed instead of the `children` */\n loading?: boolean;\n\n /** Props passed down to the `Loader` component. Ignored when `loading` prop is not set. */\n loaderProps?: LoaderProps;\n\n /** Controls width and height of the button. Numbers are converted to rem. @default 'md'. */\n size?: MantineSize | `input-${MantineSize}` | (string & {}) | number;\n\n /** Key of `theme.colors` or any valid CSS color. @default theme.primaryColor. */\n color?: MantineColor;\n\n /** Key of `theme.radius` or any valid CSS value to set border-radius. Numbers are converted to rem. @default theme.defaultRadius */\n radius?: MantineRadius;\n\n /** Gradient values used with `variant=\"gradient\"`. @default theme.defaultGradient. */\n gradient?: MantineGradient;\n\n /** Sets `disabled` attribute, prevents interactions */\n disabled?: boolean;\n\n /** Icon element */\n children?: React.ReactNode;\n\n /** If set, adjusts text color based on background color for `filled` variant */\n autoContrast?: boolean;\n}\n\nexport type ActionIconFactory = PolymorphicFactory<{\n props: ActionIconProps;\n defaultComponent: 'button';\n defaultRef: HTMLButtonElement;\n stylesNames: ActionIconStylesNames;\n variant: ActionIconVariant;\n vars: ActionIconCssVariables;\n staticComponents: {\n Group: typeof ActionIconGroup;\n GroupSection: typeof ActionIconGroupSection;\n };\n}>;\n\nconst varsResolver = createVarsResolver<ActionIconFactory>(\n (theme, { size, radius, variant, gradient, color, autoContrast }) => {\n const colors = theme.variantColorResolver({\n color: color || theme.primaryColor,\n theme,\n gradient,\n variant: variant || 'filled',\n autoContrast,\n });\n\n return {\n root: {\n '--ai-size': getSize(size, 'ai-size'),\n '--ai-radius': radius === undefined ? undefined : getRadius(radius),\n '--ai-bg': color || variant ? colors.background : undefined,\n '--ai-hover': color || variant ? colors.hover : undefined,\n '--ai-hover-color': color || variant ? colors.hoverColor : undefined,\n '--ai-color': colors.color,\n '--ai-bd': color || variant ? colors.border : undefined,\n },\n };\n }\n);\n\nexport const ActionIcon = polymorphicFactory<ActionIconFactory>((_props) => {\n const props = useProps('ActionIcon', null, _props);\n const {\n className,\n unstyled,\n variant,\n classNames,\n styles,\n style,\n loading,\n loaderProps,\n size,\n color,\n radius,\n __staticSelector,\n gradient,\n vars,\n children,\n disabled,\n 'data-disabled': dataDisabled,\n autoContrast,\n mod,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<ActionIconFactory>({\n name: ['ActionIcon', __staticSelector],\n props,\n className,\n style,\n classes,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n return (\n <UnstyledButton\n {...getStyles('root', { active: !disabled && !loading && !dataDisabled })}\n {...others}\n unstyled={unstyled}\n variant={variant}\n size={size}\n disabled={disabled || loading}\n mod={[{ loading, disabled: disabled || dataDisabled }, mod]}\n >\n {typeof loading === 'boolean' && (\n <Transition mounted={loading} transition=\"slide-down\" duration={150}>\n {(transitionStyles) => (\n <Box component=\"span\" {...getStyles('loader', { style: transitionStyles })} aria-hidden>\n <Loader color=\"var(--ai-color)\" size=\"calc(var(--ai-size) * 0.55)\" {...loaderProps} />\n </Box>\n )}\n </Transition>\n )}\n\n <Box component=\"span\" mod={{ loading }} {...getStyles('icon')}>\n {children}\n </Box>\n </UnstyledButton>\n );\n});\n\nActionIcon.classes = classes;\nActionIcon.varsResolver = varsResolver;\nActionIcon.displayName = '@mantine/core/ActionIcon';\nActionIcon.Group = ActionIconGroup;\nActionIcon.GroupSection = ActionIconGroupSection;\n\nexport namespace ActionIcon {\n export type Props = ActionIconProps;\n export type StylesNames = ActionIconStylesNames;\n export type CssVariables = ActionIconCssVariables;\n export type Factory = ActionIconFactory;\n\n export namespace Group {\n export type Props = ActionIconGroupProps;\n export type StylesNames = ActionIconGroupStylesNames;\n export type CssVariables = ActionIconGroupCssVariables;\n export type Factory = ActionIconGroupFactory;\n }\n\n export namespace GroupSection {\n export type Props = ActionIconGroupSectionProps;\n export type StylesNames = ActionIconGroupSectionStylesNames;\n export type CssVariables = ActionIconGroupSectionCssVariables;\n export type Factory = ActionIconGroupSectionFactory;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqGA,MAAM,eAAeA,6BAAAA,oBAClB,OAAO,EAAE,MAAM,QAAQ,SAAS,UAAU,OAAO,mBAAmB;CACnE,MAAM,SAAS,MAAM,qBAAqB;EACxC,OAAO,SAAS,MAAM;EACtB;EACA;EACA,SA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