@mantine/core 9.5.1-alpha.1 → 9.5.1
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/cjs/components/Cascader/Cascader.cjs +4 -2
- package/cjs/components/Cascader/Cascader.cjs.map +1 -1
- package/cjs/components/Cascader/CascaderColumns.cjs +34 -3
- package/cjs/components/Cascader/CascaderColumns.cjs.map +1 -1
- package/cjs/components/Cascader/use-cascader-safe-area.cjs +76 -0
- package/cjs/components/Cascader/use-cascader-safe-area.cjs.map +1 -0
- package/cjs/components/Checkbox/CheckboxCard/CheckboxCard.cjs +8 -4
- package/cjs/components/Checkbox/CheckboxCard/CheckboxCard.cjs.map +1 -1
- package/cjs/components/Checkbox/CheckboxIndicator/CheckboxIndicator.cjs +3 -2
- package/cjs/components/Checkbox/CheckboxIndicator/CheckboxIndicator.cjs.map +1 -1
- package/cjs/components/ColorInput/ColorInput.cjs +4 -2
- package/cjs/components/ColorInput/ColorInput.cjs.map +1 -1
- package/cjs/components/ColorPicker/ColorPicker.cjs.map +1 -1
- package/cjs/components/FloatingIndicator/use-floating-indicator.cjs +6 -4
- package/cjs/components/FloatingIndicator/use-floating-indicator.cjs.map +1 -1
- package/cjs/components/PasswordInput/PasswordInput.cjs +4 -3
- package/cjs/components/PasswordInput/PasswordInput.cjs.map +1 -1
- package/cjs/components/Tooltip/Tooltip.cjs +11 -3
- package/cjs/components/Tooltip/Tooltip.cjs.map +1 -1
- package/cjs/components/Tooltip/Tooltip.module.cjs.map +1 -1
- package/cjs/components/Tooltip/use-tooltip.cjs +2 -1
- package/cjs/components/Tooltip/use-tooltip.cjs.map +1 -1
- package/esm/components/Cascader/Cascader.mjs +4 -2
- package/esm/components/Cascader/Cascader.mjs.map +1 -1
- package/esm/components/Cascader/CascaderColumns.mjs +35 -4
- package/esm/components/Cascader/CascaderColumns.mjs.map +1 -1
- package/esm/components/Cascader/use-cascader-safe-area.mjs +76 -0
- package/esm/components/Cascader/use-cascader-safe-area.mjs.map +1 -0
- package/esm/components/Checkbox/CheckboxCard/CheckboxCard.mjs +8 -4
- package/esm/components/Checkbox/CheckboxCard/CheckboxCard.mjs.map +1 -1
- package/esm/components/Checkbox/CheckboxIndicator/CheckboxIndicator.mjs +3 -2
- package/esm/components/Checkbox/CheckboxIndicator/CheckboxIndicator.mjs.map +1 -1
- package/esm/components/ColorInput/ColorInput.mjs +4 -2
- package/esm/components/ColorInput/ColorInput.mjs.map +1 -1
- package/esm/components/ColorPicker/ColorPicker.mjs.map +1 -1
- package/esm/components/FloatingIndicator/use-floating-indicator.mjs +6 -4
- package/esm/components/FloatingIndicator/use-floating-indicator.mjs.map +1 -1
- package/esm/components/PasswordInput/PasswordInput.mjs +4 -3
- package/esm/components/PasswordInput/PasswordInput.mjs.map +1 -1
- package/esm/components/Tooltip/Tooltip.mjs +11 -3
- package/esm/components/Tooltip/Tooltip.mjs.map +1 -1
- package/esm/components/Tooltip/Tooltip.module.mjs.map +1 -1
- package/esm/components/Tooltip/use-tooltip.mjs +3 -2
- package/esm/components/Tooltip/use-tooltip.mjs.map +1 -1
- package/lib/components/Cascader/Cascader.d.ts +4 -0
- package/lib/components/Cascader/CascaderColumns.d.ts +3 -2
- package/lib/components/Cascader/use-cascader-safe-area.d.ts +20 -0
- package/lib/components/Checkbox/CheckboxCard/CheckboxCard.d.ts +3 -0
- package/lib/components/ColorPicker/ColorPicker.d.ts +2 -2
- package/lib/components/PasswordInput/PasswordInput.d.ts +2 -0
- package/lib/components/Tooltip/Tooltip.d.ts +2 -0
- package/lib/components/Tooltip/use-tooltip.d.ts +1 -0
- package/package.json +2 -2
- package/styles/Tooltip.css +4 -0
- package/styles/Tooltip.layer.css +4 -0
- package/styles.css +4 -0
- package/styles.layer.css +4 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorPicker.mjs","names":["classes"],"sources":["../../../src/components/ColorPicker/ColorPicker.tsx"],"sourcesContent":["import { useRef, useState } from 'react';\nimport { useDidUpdate, useUncontrolled } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n DataAttributes,\n ElementProps,\n factory,\n Factory,\n getSize,\n getSpacing,\n MantineSize,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { ColorSwatch } from '../ColorSwatch';\nimport { AlphaSlider } from './AlphaSlider/AlphaSlider';\nimport { ColorPickerContext } from './ColorPicker.context';\nimport { ColorFormat, HsvaColor } from './ColorPicker.types';\nimport { convertHsvaTo, isColorValid, parseColor } from './converters';\nimport { HueSlider } from './HueSlider/HueSlider';\nimport { Saturation } from './Saturation/Saturation';\nimport { Swatches } from './Swatches/Swatches';\nimport classes from './ColorPicker.module.css';\n\nexport type ColorPickerStylesNames =\n | 'wrapper'\n | 'preview'\n | 'body'\n | 'sliders'\n | 'slider'\n | 'sliderOverlay'\n | 'thumb'\n | 'saturation'\n | 'thumb'\n | 'saturationOverlay'\n | 'thumb'\n | 'swatches'\n | 'swatch';\n\nexport type ColorPickerCssVariables = {\n wrapper:\n | '--cp-preview-size'\n | '--cp-width'\n | '--cp-body-spacing'\n | '--cp-swatch-size'\n | '--cp-thumb-size'\n | '--cp-saturation-height';\n};\n\nexport interface __ColorPickerProps {\n /** Controlled component value */\n value?: string;\n\n /** Uncontrolled component default value */\n defaultValue?: string;\n\n /** Called when value changes */\n onChange?: (value: string) => void;\n\n /** Called when the user stops dragging one of the sliders or changes the value with keyboard */\n onChangeEnd?: (value: string) => void;\n\n /** Color format. `hexa`, `rgba`, `hsla` values render alpha channel slider @default 'hex' */\n format?: ColorFormat;\n\n /** If `false`, the component displays only swatches @default true */\n withPicker?: boolean;\n\n /** A list of colors used to display swatches list below the color picker */\n swatches?: string[];\n\n /** Number of swatches per row @default 7 */\n swatchesPerRow?: number;\n\n /** Component size @default 'md' */\n size?: MantineSize | (string & {});\n}\n\nexport interface ColorPickerProps\n extends\n BoxProps,\n __ColorPickerProps,\n StylesApiProps<ColorPickerFactory>,\n ElementProps<'div', 'onChange' | 'value' | 'defaultValue'> {\n __staticSelector?: string;\n\n /** If set, the component takes 100% width of its container @default false */\n fullWidth?: boolean;\n\n /** If set, interactive elements (sliders thumbs and swatches) are focusable with keyboard @default true */\n focusable?: boolean;\n\n /** Saturation slider `aria-label` */\n saturationLabel?: string;\n\n /** Hue slider `aria-label` */\n hueLabel?: string;\n\n /** Alpha slider `aria-label` */\n alphaLabel?: string;\n\n /** Called when one of the color swatches is clicked */\n onColorSwatchClick?: (color: string) => void;\n\n /** Hidden input `name` attribute, if not set, the input will not be rendered */\n name?: string;\n\n /** Props spread to the hidden input */\n hiddenInputProps?: React.ComponentProps<'input'> & DataAttributes;\n}\n\nexport type ColorPickerFactory = Factory<{\n props: ColorPickerProps;\n ref: HTMLDivElement;\n stylesNames: ColorPickerStylesNames;\n vars: ColorPickerCssVariables;\n}>;\n\nconst defaultProps = {\n swatchesPerRow: 7,\n withPicker: true,\n focusable: true,\n size: 'md',\n __staticSelector: 'ColorPicker',\n} satisfies Partial<ColorPickerProps>;\n\nconst varsResolver = createVarsResolver<ColorPickerFactory>((_, { size, swatchesPerRow }) => ({\n wrapper: {\n '--cp-preview-size': getSize(size, 'cp-preview-size'),\n '--cp-width': getSize(size, 'cp-width'),\n '--cp-body-spacing': getSpacing(size),\n '--cp-swatch-size': `${100 / swatchesPerRow!}%`,\n '--cp-thumb-size': getSize(size, 'cp-thumb-size'),\n '--cp-saturation-height': getSize(size, 'cp-saturation-height'),\n },\n}));\n\nexport const ColorPicker = factory<ColorPickerFactory>((_props) => {\n const props = useProps('ColorPicker', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n format = 'hex',\n value,\n defaultValue,\n onChange,\n onChangeEnd,\n withPicker,\n size,\n saturationLabel,\n hueLabel,\n alphaLabel,\n focusable,\n swatches,\n swatchesPerRow,\n fullWidth,\n onColorSwatchClick,\n __staticSelector,\n mod,\n attributes,\n name,\n hiddenInputProps,\n ...others\n } = props;\n\n const getStyles = useStyles<ColorPickerFactory>({\n name: __staticSelector,\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'wrapper',\n vars,\n varsResolver,\n });\n\n const formatRef = useRef(format || 'hex');\n const valueRef = useRef<string>('');\n const scrubTimeoutRef = useRef<number>(-1);\n const isScrubbingRef = useRef(false);\n const withAlpha = format === 'hexa' || format === 'rgba' || format === 'hsla';\n\n const [_value, setValue, controlled] = useUncontrolled({\n value,\n defaultValue,\n finalValue: '#FFFFFF',\n onChange,\n });\n\n const [parsed, setParsed] = useState<HsvaColor>(parseColor(_value));\n\n const startScrubbing = () => {\n window.clearTimeout(scrubTimeoutRef.current);\n isScrubbingRef.current = true;\n };\n\n const stopScrubbing = () => {\n window.clearTimeout(scrubTimeoutRef.current);\n scrubTimeoutRef.current = window.setTimeout(() => {\n isScrubbingRef.current = false;\n }, 200);\n };\n\n const handleChange = (color: Partial<HsvaColor>) => {\n setParsed((current) => {\n const next = { ...current, ...color };\n valueRef.current = convertHsvaTo(formatRef.current, next);\n return next;\n });\n\n setValue(valueRef.current);\n };\n\n useDidUpdate(() => {\n if (typeof value === 'string' && isColorValid(value) && !isScrubbingRef.current) {\n setParsed(parseColor(value));\n }\n }, [value]);\n\n useDidUpdate(() => {\n formatRef.current = format || 'hex';\n setValue(convertHsvaTo(formatRef.current, parsed));\n }, [format]);\n\n return (\n <ColorPickerContext value={{ getStyles, unstyled }}>\n <Box\n {...getStyles('wrapper')}\n size={size}\n mod={[{ 'full-width': fullWidth }, mod]}\n {...others}\n >\n {name && <input type=\"hidden\" name={name} value={_value} {...hiddenInputProps} />}\n\n {withPicker && (\n <>\n <Saturation\n value={parsed}\n onChange={handleChange}\n onChangeEnd={({ s, v }) =>\n onChangeEnd?.(convertHsvaTo(formatRef.current, { ...parsed, s: s!, v: v! }))\n }\n color={_value}\n size={size}\n focusable={focusable}\n saturationLabel={saturationLabel}\n onScrubStart={startScrubbing}\n onScrubEnd={stopScrubbing}\n />\n\n <div {...getStyles('body')}>\n <div {...getStyles('sliders')}>\n <HueSlider\n value={parsed.h}\n onChange={(h) => handleChange({ h })}\n onChangeEnd={(h) =>\n onChangeEnd?.(convertHsvaTo(formatRef.current, { ...parsed, h }))\n }\n size={size}\n focusable={focusable}\n aria-label={hueLabel}\n onScrubStart={startScrubbing}\n onScrubEnd={stopScrubbing}\n />\n\n {withAlpha && (\n <AlphaSlider\n value={parsed.a}\n onChange={(a) => handleChange({ a })}\n onChangeEnd={(a) => {\n onChangeEnd?.(convertHsvaTo(formatRef.current, { ...parsed, a }));\n }}\n size={size}\n color={convertHsvaTo('hex', parsed)}\n focusable={focusable}\n aria-label={alphaLabel}\n onScrubStart={startScrubbing}\n onScrubEnd={stopScrubbing}\n />\n )}\n </div>\n\n {withAlpha && (\n <ColorSwatch\n color={_value}\n radius=\"sm\"\n size=\"var(--cp-preview-size)\"\n {...getStyles('preview')}\n />\n )}\n </div>\n </>\n )}\n\n {Array.isArray(swatches) && (\n <Swatches\n data={swatches}\n swatchesPerRow={swatchesPerRow}\n focusable={focusable}\n setValue={setValue}\n value={_value}\n onChangeEnd={(color) => {\n const convertedColor = convertHsvaTo(format, parseColor(color));\n onColorSwatchClick?.(convertedColor);\n onChangeEnd?.(convertedColor);\n if (!controlled) {\n setParsed(parseColor(color));\n }\n }}\n />\n )}\n </Box>\n </ColorPickerContext>\n );\n});\n\nColorPicker.classes = classes;\nColorPicker.varsResolver = varsResolver;\nColorPicker.displayName = '@mantine/core/ColorPicker';\n\nexport namespace ColorPicker {\n export type Props = ColorPickerProps;\n export type CssVariables = ColorPickerCssVariables;\n export type Factory = ColorPickerFactory;\n export type StylesNames = ColorPickerStylesNames;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyHA,MAAM,eAAe;CACnB,gBAAgB;CAChB,YAAY;CACZ,WAAW;CACX,MAAM;CACN,kBAAkB;AACpB;AAEA,MAAM,eAAe,oBAAwC,GAAG,EAAE,MAAM,sBAAsB,EAC5F,SAA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,SAAS;SAAE,GAAG;SAAQ;QAAE,CAAC,CAAC;OAClE;OACM;OACN,OAAO,cAAc,OAAO,MAAM;OACvB;OACX,cAAY;OACZ,cAAc;OACd,YAAY;MACb,CAAA,CAEA;SAEJ,aACC,oBAAC,aAAD;MACE,OAAO;MACP,QAAO;MACP,MAAK;MACL,GAAI,UAAU,SAAS;KACxB,CAAA,CAEA;MACL,EAAA,CAAA;IAGH,MAAM,QAAQ,QAAQ,KACrB,oBAAC,UAAD;KACE,MAAM;KACU;KACL;KACD;KACV,OAAO;KACP,cAAc,UAAU;MACtB,MAAM,iBAAiB,cAAc,QAAQ,WAAW,KAAK,CAAC;MAC9D,qBAAqB,cAAc;MACnC,cAAc,cAAc;MAC5B,IAAI,CAAC,YACH,UAAU,WAAW,KAAK,CAAC;KAE/B;IACD,CAAA;GAEA;;CACa,CAAA;AAExB,CAAC;AAED,YAAY,UAAUA;AACtB,YAAY,eAAe;AAC3B,YAAY,cAAc"}
|
|
1
|
+
{"version":3,"file":"ColorPicker.mjs","names":["classes"],"sources":["../../../src/components/ColorPicker/ColorPicker.tsx"],"sourcesContent":["import { useRef, useState } from 'react';\nimport { useDidUpdate, useUncontrolled } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n DataAttributes,\n ElementProps,\n factory,\n Factory,\n getSize,\n getSpacing,\n MantineSize,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { ColorSwatch } from '../ColorSwatch';\nimport { AlphaSlider } from './AlphaSlider/AlphaSlider';\nimport { ColorPickerContext } from './ColorPicker.context';\nimport { ColorFormat, HsvaColor } from './ColorPicker.types';\nimport { convertHsvaTo, isColorValid, parseColor } from './converters';\nimport { HueSlider } from './HueSlider/HueSlider';\nimport { Saturation } from './Saturation/Saturation';\nimport { Swatches } from './Swatches/Swatches';\nimport classes from './ColorPicker.module.css';\n\nexport type ColorPickerStylesNames =\n | 'wrapper'\n | 'preview'\n | 'body'\n | 'sliders'\n | 'slider'\n | 'sliderOverlay'\n | 'thumb'\n | 'saturation'\n | 'thumb'\n | 'saturationOverlay'\n | 'thumb'\n | 'swatches'\n | 'swatch';\n\nexport type ColorPickerCssVariables = {\n wrapper:\n | '--cp-preview-size'\n | '--cp-width'\n | '--cp-body-spacing'\n | '--cp-swatch-size'\n | '--cp-thumb-size'\n | '--cp-saturation-height';\n};\n\nexport interface __ColorPickerProps {\n /** Controlled component value */\n value?: string;\n\n /** Uncontrolled component default value */\n defaultValue?: string;\n\n /** Called when value changes */\n onChange?: (value: string) => void;\n\n /** Called when the user stops dragging one of the sliders or changes the value with keyboard */\n onChangeEnd?: (value: string) => void;\n\n /** Color format. `hexa`, `rgba`, `hsla` values render alpha channel slider @default 'hex' */\n format?: ColorFormat;\n\n /** If `false`, the component displays only swatches @default true */\n withPicker?: boolean;\n\n /** A list of colors used to display swatches list below the color picker */\n swatches?: string[];\n\n /** Number of swatches per row @default 7 */\n swatchesPerRow?: number;\n\n /** Component size @default 'md' */\n size?: MantineSize | (string & {});\n\n /** If set, the component takes 100% width of its container @default false */\n fullWidth?: boolean;\n}\n\nexport interface ColorPickerProps\n extends\n BoxProps,\n __ColorPickerProps,\n StylesApiProps<ColorPickerFactory>,\n ElementProps<'div', 'onChange' | 'value' | 'defaultValue'> {\n __staticSelector?: string;\n\n /** If set, interactive elements (sliders thumbs and swatches) are focusable with keyboard @default true */\n focusable?: boolean;\n\n /** Saturation slider `aria-label` */\n saturationLabel?: string;\n\n /** Hue slider `aria-label` */\n hueLabel?: string;\n\n /** Alpha slider `aria-label` */\n alphaLabel?: string;\n\n /** Called when one of the color swatches is clicked */\n onColorSwatchClick?: (color: string) => void;\n\n /** Hidden input `name` attribute, if not set, the input will not be rendered */\n name?: string;\n\n /** Props spread to the hidden input */\n hiddenInputProps?: React.ComponentProps<'input'> & DataAttributes;\n}\n\nexport type ColorPickerFactory = Factory<{\n props: ColorPickerProps;\n ref: HTMLDivElement;\n stylesNames: ColorPickerStylesNames;\n vars: ColorPickerCssVariables;\n}>;\n\nconst defaultProps = {\n swatchesPerRow: 7,\n withPicker: true,\n focusable: true,\n size: 'md',\n __staticSelector: 'ColorPicker',\n} satisfies Partial<ColorPickerProps>;\n\nconst varsResolver = createVarsResolver<ColorPickerFactory>((_, { size, swatchesPerRow }) => ({\n wrapper: {\n '--cp-preview-size': getSize(size, 'cp-preview-size'),\n '--cp-width': getSize(size, 'cp-width'),\n '--cp-body-spacing': getSpacing(size),\n '--cp-swatch-size': `${100 / swatchesPerRow!}%`,\n '--cp-thumb-size': getSize(size, 'cp-thumb-size'),\n '--cp-saturation-height': getSize(size, 'cp-saturation-height'),\n },\n}));\n\nexport const ColorPicker = factory<ColorPickerFactory>((_props) => {\n const props = useProps('ColorPicker', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n format = 'hex',\n value,\n defaultValue,\n onChange,\n onChangeEnd,\n withPicker,\n size,\n saturationLabel,\n hueLabel,\n alphaLabel,\n focusable,\n swatches,\n swatchesPerRow,\n fullWidth,\n onColorSwatchClick,\n __staticSelector,\n mod,\n attributes,\n name,\n hiddenInputProps,\n ...others\n } = props;\n\n const getStyles = useStyles<ColorPickerFactory>({\n name: __staticSelector,\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'wrapper',\n vars,\n varsResolver,\n });\n\n const formatRef = useRef(format || 'hex');\n const valueRef = useRef<string>('');\n const scrubTimeoutRef = useRef<number>(-1);\n const isScrubbingRef = useRef(false);\n const withAlpha = format === 'hexa' || format === 'rgba' || format === 'hsla';\n\n const [_value, setValue, controlled] = useUncontrolled({\n value,\n defaultValue,\n finalValue: '#FFFFFF',\n onChange,\n });\n\n const [parsed, setParsed] = useState<HsvaColor>(parseColor(_value));\n\n const startScrubbing = () => {\n window.clearTimeout(scrubTimeoutRef.current);\n isScrubbingRef.current = true;\n };\n\n const stopScrubbing = () => {\n window.clearTimeout(scrubTimeoutRef.current);\n scrubTimeoutRef.current = window.setTimeout(() => {\n isScrubbingRef.current = false;\n }, 200);\n };\n\n const handleChange = (color: Partial<HsvaColor>) => {\n setParsed((current) => {\n const next = { ...current, ...color };\n valueRef.current = convertHsvaTo(formatRef.current, next);\n return next;\n });\n\n setValue(valueRef.current);\n };\n\n useDidUpdate(() => {\n if (typeof value === 'string' && isColorValid(value) && !isScrubbingRef.current) {\n setParsed(parseColor(value));\n }\n }, [value]);\n\n useDidUpdate(() => {\n formatRef.current = format || 'hex';\n setValue(convertHsvaTo(formatRef.current, parsed));\n }, [format]);\n\n return (\n <ColorPickerContext value={{ getStyles, unstyled }}>\n <Box\n {...getStyles('wrapper')}\n size={size}\n mod={[{ 'full-width': fullWidth }, mod]}\n {...others}\n >\n {name && <input type=\"hidden\" name={name} value={_value} {...hiddenInputProps} />}\n\n {withPicker && (\n <>\n <Saturation\n value={parsed}\n onChange={handleChange}\n onChangeEnd={({ s, v }) =>\n onChangeEnd?.(convertHsvaTo(formatRef.current, { ...parsed, s: s!, v: v! }))\n }\n color={_value}\n size={size}\n focusable={focusable}\n saturationLabel={saturationLabel}\n onScrubStart={startScrubbing}\n onScrubEnd={stopScrubbing}\n />\n\n <div {...getStyles('body')}>\n <div {...getStyles('sliders')}>\n <HueSlider\n value={parsed.h}\n onChange={(h) => handleChange({ h })}\n onChangeEnd={(h) =>\n onChangeEnd?.(convertHsvaTo(formatRef.current, { ...parsed, h }))\n }\n size={size}\n focusable={focusable}\n aria-label={hueLabel}\n onScrubStart={startScrubbing}\n onScrubEnd={stopScrubbing}\n />\n\n {withAlpha && (\n <AlphaSlider\n value={parsed.a}\n onChange={(a) => handleChange({ a })}\n onChangeEnd={(a) => {\n onChangeEnd?.(convertHsvaTo(formatRef.current, { ...parsed, a }));\n }}\n size={size}\n color={convertHsvaTo('hex', parsed)}\n focusable={focusable}\n aria-label={alphaLabel}\n onScrubStart={startScrubbing}\n onScrubEnd={stopScrubbing}\n />\n )}\n </div>\n\n {withAlpha && (\n <ColorSwatch\n color={_value}\n radius=\"sm\"\n size=\"var(--cp-preview-size)\"\n {...getStyles('preview')}\n />\n )}\n </div>\n </>\n )}\n\n {Array.isArray(swatches) && (\n <Swatches\n data={swatches}\n swatchesPerRow={swatchesPerRow}\n focusable={focusable}\n setValue={setValue}\n value={_value}\n onChangeEnd={(color) => {\n const convertedColor = convertHsvaTo(format, parseColor(color));\n onColorSwatchClick?.(convertedColor);\n onChangeEnd?.(convertedColor);\n if (!controlled) {\n setParsed(parseColor(color));\n }\n }}\n />\n )}\n </Box>\n </ColorPickerContext>\n );\n});\n\nColorPicker.classes = classes;\nColorPicker.varsResolver = varsResolver;\nColorPicker.displayName = '@mantine/core/ColorPicker';\n\nexport namespace ColorPicker {\n export type Props = ColorPickerProps;\n export type CssVariables = ColorPickerCssVariables;\n export type Factory = ColorPickerFactory;\n export type StylesNames = ColorPickerStylesNames;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyHA,MAAM,eAAe;CACnB,gBAAgB;CAChB,YAAY;CACZ,WAAW;CACX,MAAM;CACN,kBAAkB;AACpB;AAEA,MAAM,eAAe,oBAAwC,GAAG,EAAE,MAAM,sBAAsB,EAC5F,SAAS;CACP,qBAAqB,QAAQ,MAAM,iBAAiB;CACpD,cAAc,QAAQ,MAAM,UAAU;CACtC,qBAAqB,WAAW,IAAI;CACpC,oBAAoB,GAAG,MAAM,eAAgB;CAC7C,mBAAmB,QAAQ,MAAM,eAAe;CAChD,0BAA0B,QAAQ,MAAM,sBAAsB;AAChE,EACF,EAAE;AAEF,MAAa,cAAc,SAA6B,WAAW;CACjE,MAAM,QAAQ,SAAS,eAAe,cAAc,MAAM;CAC1D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,SAAS,OACT,OACA,cACA,UACA,aACA,YACA,MACA,iBACA,UACA,YACA,WACA,UACA,gBACA,WACA,oBACA,kBACA,KACA,YACA,MACA,kBACA,GAAG,WACD;CAEJ,MAAM,YAAY,UAA8B;EAC9C,MAAM;EACN;EACA,SAAA;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AEA;;CACa,CAAA;AAExB,CAAC;AAED,YAAY,UAAUA;AACtB,YAAY,eAAe;AAC3B,YAAY,cAAc"}
|
|
@@ -22,15 +22,17 @@ function useFloatingIndicator({ target, parent, ref, displayAfterTransitionEnd,
|
|
|
22
22
|
if (!target || !parent || !ref.current) return;
|
|
23
23
|
const targetRect = target.getBoundingClientRect();
|
|
24
24
|
const parentRect = parent.getBoundingClientRect();
|
|
25
|
+
const scaleX = parent.offsetWidth === 0 ? 1 : parentRect.width / parent.offsetWidth;
|
|
26
|
+
const scaleY = parent.offsetHeight === 0 ? 1 : parentRect.height / parent.offsetHeight;
|
|
25
27
|
const targetComputedStyle = window.getComputedStyle(target);
|
|
26
28
|
const parentComputedStyle = window.getComputedStyle(parent);
|
|
27
29
|
const borderTopWidth = toInt(targetComputedStyle.borderTopWidth) + toInt(parentComputedStyle.borderTopWidth);
|
|
28
30
|
const borderLeftWidth = toInt(targetComputedStyle.borderLeftWidth) + toInt(parentComputedStyle.borderLeftWidth);
|
|
29
31
|
const position = {
|
|
30
|
-
top: targetRect.top - parentRect.top - borderTopWidth,
|
|
31
|
-
left: targetRect.left - parentRect.left - borderLeftWidth,
|
|
32
|
-
width: targetRect.width,
|
|
33
|
-
height: targetRect.height
|
|
32
|
+
top: (targetRect.top - parentRect.top) / scaleY - borderTopWidth,
|
|
33
|
+
left: (targetRect.left - parentRect.left) / scaleX - borderLeftWidth,
|
|
34
|
+
width: targetRect.width / scaleX,
|
|
35
|
+
height: targetRect.height / scaleY
|
|
34
36
|
};
|
|
35
37
|
ref.current.style.transform = `translateY(${position.top}px) translateX(${position.left}px)`;
|
|
36
38
|
ref.current.style.width = `${position.width}px`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-floating-indicator.mjs","names":[],"sources":["../../../src/components/FloatingIndicator/use-floating-indicator.ts"],"sourcesContent":["import { useEffect, useRef, useState, type RefObject } from 'react';\nimport { useMutationObserverTarget, useTimeout } from '@mantine/hooks';\nimport { getEnv } from '../../core';\nimport { toInt } from '../ScrollArea/utils';\n\nfunction isParent(\n parentElement: HTMLElement | EventTarget | null,\n childElement: HTMLElement | null\n) {\n if (!childElement || !parentElement) {\n return false;\n }\n\n let parent = childElement.parentNode;\n while (parent != null) {\n if (parent === parentElement) {\n return true;\n }\n parent = parent.parentNode;\n }\n return false;\n}\n\ninterface UseFloatingIndicatorInput {\n target: HTMLElement | null | undefined;\n parent: HTMLElement | null | undefined;\n ref: RefObject<HTMLElement | null>;\n displayAfterTransitionEnd?: boolean;\n onTransitionStart?: () => void;\n onTransitionEnd?: () => void;\n}\n\nexport function useFloatingIndicator({\n target,\n parent,\n ref,\n displayAfterTransitionEnd,\n onTransitionStart,\n onTransitionEnd,\n}: UseFloatingIndicatorInput) {\n const transitionTimeout = useRef<number>(-1);\n const previousTarget = useRef<HTMLElement | null | undefined>(target);\n const [initialized, setInitialized] = useState(false);\n\n const [hidden, setHidden] = useState(\n typeof displayAfterTransitionEnd === 'boolean' ? displayAfterTransitionEnd : false\n );\n\n const updatePosition = () => {\n if (!target || !parent || !ref.current) {\n return;\n }\n\n const targetRect = target.getBoundingClientRect();\n const parentRect = parent.getBoundingClientRect();\n\n const targetComputedStyle = window.getComputedStyle(target);\n const parentComputedStyle = window.getComputedStyle(parent);\n\n const borderTopWidth =\n toInt(targetComputedStyle.borderTopWidth) + toInt(parentComputedStyle.borderTopWidth);\n const borderLeftWidth =\n toInt(targetComputedStyle.borderLeftWidth) + toInt(parentComputedStyle.borderLeftWidth);\n\n const position = {\n top: targetRect.top - parentRect.top - borderTopWidth,\n left: targetRect.left - parentRect.left - borderLeftWidth,\n width: targetRect.width,\n height: targetRect.height,\n };\n\n ref.current.style.transform = `translateY(${position.top}px) translateX(${position.left}px)`;\n ref.current.style.width = `${position.width}px`;\n ref.current.style.height = `${position.height}px`;\n };\n\n const updatePositionWithoutAnimation = () => {\n window.clearTimeout(transitionTimeout.current);\n if (ref.current) {\n ref.current.style.transitionDuration = '0ms';\n }\n updatePosition();\n transitionTimeout.current = window.setTimeout(() => {\n if (ref.current) {\n ref.current.style.transitionDuration = '';\n }\n }, 30);\n };\n\n const targetResizeObserver = useRef<ResizeObserver>(null);\n const parentResizeObserver = useRef<ResizeObserver>(null);\n\n useEffect(() => {\n if (initialized && previousTarget.current !== target && onTransitionStart) {\n onTransitionStart();\n }\n\n previousTarget.current = target;\n updatePosition();\n\n if (target) {\n targetResizeObserver.current = new ResizeObserver(updatePositionWithoutAnimation);\n targetResizeObserver.current.observe(target);\n\n if (parent) {\n parentResizeObserver.current = new ResizeObserver(updatePositionWithoutAnimation);\n parentResizeObserver.current.observe(parent);\n }\n\n return () => {\n targetResizeObserver.current?.disconnect();\n parentResizeObserver.current?.disconnect();\n };\n }\n\n return undefined;\n }, [parent, target]);\n\n useEffect(() => {\n if (parent) {\n const handleTransitionEnd = (event: TransitionEvent) => {\n if (isParent(event.target, parent)) {\n updatePositionWithoutAnimation();\n setHidden(false);\n }\n };\n\n parent.addEventListener('transitionend', handleTransitionEnd);\n return () => {\n parent.removeEventListener('transitionend', handleTransitionEnd);\n };\n }\n\n return undefined;\n }, [parent]);\n\n useEffect(() => {\n if (ref.current && onTransitionEnd) {\n const handleIndicatorTransitionEnd = (event: TransitionEvent) => {\n if (event.propertyName === 'transform') {\n onTransitionEnd();\n }\n };\n\n ref.current.addEventListener('transitionend', handleIndicatorTransitionEnd);\n return () => {\n ref.current?.removeEventListener('transitionend', handleIndicatorTransitionEnd);\n };\n }\n\n return undefined;\n }, [onTransitionEnd]);\n\n useTimeout(\n () => {\n // Prevents warning about state update without act\n if (getEnv() !== 'test') {\n setInitialized(true);\n }\n },\n 20,\n { autoInvoke: true }\n );\n\n useMutationObserverTarget(\n (mutations) => {\n mutations.forEach((mutation) => {\n if (mutation.type === 'attributes' && mutation.attributeName === 'dir') {\n updatePositionWithoutAnimation();\n }\n });\n },\n { attributes: true, attributeFilter: ['dir'] },\n () => document.documentElement\n );\n\n return { initialized, hidden };\n}\n"],"mappings":";;;;;;AAKA,SAAS,SACP,eACA,cACA;CACA,IAAI,CAAC,gBAAgB,CAAC,eACpB,OAAO;CAGT,IAAI,SAAS,aAAa;CAC1B,OAAO,UAAU,MAAM;EACrB,IAAI,WAAW,eACb,OAAO;EAET,SAAS,OAAO;CAClB;CACA,OAAO;AACT;AAWA,SAAgB,qBAAqB,EACnC,QACA,QACA,KACA,2BACA,mBACA,mBAC4B;CAC5B,MAAM,oBAAoB,OAAe,EAAE;CAC3C,MAAM,iBAAiB,OAAuC,MAAM;CACpE,MAAM,CAAC,aAAa,kBAAkB,SAAS,KAAK;CAEpD,MAAM,CAAC,QAAQ,aAAa,SAC1B,OAAO,8BAA8B,YAAY,4BAA4B,KAC/E;CAEA,MAAM,uBAAuB;EAC3B,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,SAC7B;EAGF,MAAM,aAAa,OAAO,sBAAsB;EAChD,MAAM,aAAa,OAAO,sBAAsB;EAEhD,MAAM,sBAAsB,OAAO,iBAAiB,MAAM;EAC1D,MAAM,sBAAsB,OAAO,iBAAiB,MAAM;EAE1D,MAAM,iBACJ,MAAM,oBAAoB,cAAc,IAAI,MAAM,oBAAoB,cAAc;EACtF,MAAM,kBACJ,MAAM,oBAAoB,eAAe,IAAI,MAAM,oBAAoB,eAAe;EAExF,MAAM,WAAW;GACf,
|
|
1
|
+
{"version":3,"file":"use-floating-indicator.mjs","names":[],"sources":["../../../src/components/FloatingIndicator/use-floating-indicator.ts"],"sourcesContent":["import { useEffect, useRef, useState, type RefObject } from 'react';\nimport { useMutationObserverTarget, useTimeout } from '@mantine/hooks';\nimport { getEnv } from '../../core';\nimport { toInt } from '../ScrollArea/utils';\n\nfunction isParent(\n parentElement: HTMLElement | EventTarget | null,\n childElement: HTMLElement | null\n) {\n if (!childElement || !parentElement) {\n return false;\n }\n\n let parent = childElement.parentNode;\n while (parent != null) {\n if (parent === parentElement) {\n return true;\n }\n parent = parent.parentNode;\n }\n return false;\n}\n\ninterface UseFloatingIndicatorInput {\n target: HTMLElement | null | undefined;\n parent: HTMLElement | null | undefined;\n ref: RefObject<HTMLElement | null>;\n displayAfterTransitionEnd?: boolean;\n onTransitionStart?: () => void;\n onTransitionEnd?: () => void;\n}\n\nexport function useFloatingIndicator({\n target,\n parent,\n ref,\n displayAfterTransitionEnd,\n onTransitionStart,\n onTransitionEnd,\n}: UseFloatingIndicatorInput) {\n const transitionTimeout = useRef<number>(-1);\n const previousTarget = useRef<HTMLElement | null | undefined>(target);\n const [initialized, setInitialized] = useState(false);\n\n const [hidden, setHidden] = useState(\n typeof displayAfterTransitionEnd === 'boolean' ? displayAfterTransitionEnd : false\n );\n\n const updatePosition = () => {\n if (!target || !parent || !ref.current) {\n return;\n }\n\n const targetRect = target.getBoundingClientRect();\n const parentRect = parent.getBoundingClientRect();\n\n const scaleX = parent.offsetWidth === 0 ? 1 : parentRect.width / parent.offsetWidth;\n const scaleY = parent.offsetHeight === 0 ? 1 : parentRect.height / parent.offsetHeight;\n\n const targetComputedStyle = window.getComputedStyle(target);\n const parentComputedStyle = window.getComputedStyle(parent);\n\n const borderTopWidth =\n toInt(targetComputedStyle.borderTopWidth) + toInt(parentComputedStyle.borderTopWidth);\n const borderLeftWidth =\n toInt(targetComputedStyle.borderLeftWidth) + toInt(parentComputedStyle.borderLeftWidth);\n\n const position = {\n top: (targetRect.top - parentRect.top) / scaleY - borderTopWidth,\n left: (targetRect.left - parentRect.left) / scaleX - borderLeftWidth,\n width: targetRect.width / scaleX,\n height: targetRect.height / scaleY,\n };\n\n ref.current.style.transform = `translateY(${position.top}px) translateX(${position.left}px)`;\n ref.current.style.width = `${position.width}px`;\n ref.current.style.height = `${position.height}px`;\n };\n\n const updatePositionWithoutAnimation = () => {\n window.clearTimeout(transitionTimeout.current);\n if (ref.current) {\n ref.current.style.transitionDuration = '0ms';\n }\n updatePosition();\n transitionTimeout.current = window.setTimeout(() => {\n if (ref.current) {\n ref.current.style.transitionDuration = '';\n }\n }, 30);\n };\n\n const targetResizeObserver = useRef<ResizeObserver>(null);\n const parentResizeObserver = useRef<ResizeObserver>(null);\n\n useEffect(() => {\n if (initialized && previousTarget.current !== target && onTransitionStart) {\n onTransitionStart();\n }\n\n previousTarget.current = target;\n updatePosition();\n\n if (target) {\n targetResizeObserver.current = new ResizeObserver(updatePositionWithoutAnimation);\n targetResizeObserver.current.observe(target);\n\n if (parent) {\n parentResizeObserver.current = new ResizeObserver(updatePositionWithoutAnimation);\n parentResizeObserver.current.observe(parent);\n }\n\n return () => {\n targetResizeObserver.current?.disconnect();\n parentResizeObserver.current?.disconnect();\n };\n }\n\n return undefined;\n }, [parent, target]);\n\n useEffect(() => {\n if (parent) {\n const handleTransitionEnd = (event: TransitionEvent) => {\n if (isParent(event.target, parent)) {\n updatePositionWithoutAnimation();\n setHidden(false);\n }\n };\n\n parent.addEventListener('transitionend', handleTransitionEnd);\n return () => {\n parent.removeEventListener('transitionend', handleTransitionEnd);\n };\n }\n\n return undefined;\n }, [parent]);\n\n useEffect(() => {\n if (ref.current && onTransitionEnd) {\n const handleIndicatorTransitionEnd = (event: TransitionEvent) => {\n if (event.propertyName === 'transform') {\n onTransitionEnd();\n }\n };\n\n ref.current.addEventListener('transitionend', handleIndicatorTransitionEnd);\n return () => {\n ref.current?.removeEventListener('transitionend', handleIndicatorTransitionEnd);\n };\n }\n\n return undefined;\n }, [onTransitionEnd]);\n\n useTimeout(\n () => {\n // Prevents warning about state update without act\n if (getEnv() !== 'test') {\n setInitialized(true);\n }\n },\n 20,\n { autoInvoke: true }\n );\n\n useMutationObserverTarget(\n (mutations) => {\n mutations.forEach((mutation) => {\n if (mutation.type === 'attributes' && mutation.attributeName === 'dir') {\n updatePositionWithoutAnimation();\n }\n });\n },\n { attributes: true, attributeFilter: ['dir'] },\n () => document.documentElement\n );\n\n return { initialized, hidden };\n}\n"],"mappings":";;;;;;AAKA,SAAS,SACP,eACA,cACA;CACA,IAAI,CAAC,gBAAgB,CAAC,eACpB,OAAO;CAGT,IAAI,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,eAAe,IAAI;CAEvB,GACA,IACA,EAAE,YAAY,KAAK,CACrB;CAEA,2BACG,cAAc;EACb,UAAU,SAAS,aAAa;GAC9B,IAAI,SAAS,SAAS,gBAAgB,SAAS,kBAAkB,OAC/D,+BAA+B;EAEnC,CAAC;CACH,GACA;EAAE,YAAY;EAAM,iBAAiB,CAAC,KAAK;CAAE,SACvC,SAAS,eACjB;CAEA,OAAO;EAAE;EAAa;CAAO;AAC/B"}
|
|
@@ -17,6 +17,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
17
17
|
//#region packages/@mantine/core/src/components/PasswordInput/PasswordInput.tsx
|
|
18
18
|
const defaultProps = {
|
|
19
19
|
visibilityToggleIcon: PasswordToggleIcon,
|
|
20
|
+
visibilityToggleFocusable: false,
|
|
20
21
|
size: "sm"
|
|
21
22
|
};
|
|
22
23
|
const varsResolver = createVarsResolver((_, { size }) => ({ root: {
|
|
@@ -29,7 +30,7 @@ const PasswordInput = factory((_props) => {
|
|
|
29
30
|
"InputWrapper",
|
|
30
31
|
"PasswordInput"
|
|
31
32
|
], defaultProps, _props);
|
|
32
|
-
const { classNames, className, style, styles, unstyled, vars, required, error, success, leftSection, disabled, id, variant, inputContainer, description, label, size, errorProps, successProps, descriptionProps, labelProps, withAsterisk, inputWrapperOrder, wrapperProps, radius, rightSection, rightSectionWidth, rightSectionPointerEvents, leftSectionWidth, visible, defaultVisible, onVisibilityChange, visibilityToggleIcon: VisibilityToggleIcon, visibilityToggleButtonProps, rightSectionProps, leftSectionProps, leftSectionPointerEvents, withErrorStyles, withSuccessStyles, mod, attributes, dir, ...others } = props;
|
|
33
|
+
const { classNames, className, style, styles, unstyled, vars, required, error, success, leftSection, disabled, id, variant, inputContainer, description, label, size, errorProps, successProps, descriptionProps, labelProps, withAsterisk, inputWrapperOrder, wrapperProps, radius, rightSection, rightSectionWidth, rightSectionPointerEvents, leftSectionWidth, visible, defaultVisible, onVisibilityChange, visibilityToggleIcon: VisibilityToggleIcon, visibilityToggleButtonProps, visibilityToggleFocusable, rightSectionProps, leftSectionProps, leftSectionPointerEvents, withErrorStyles, withSuccessStyles, mod, attributes, dir, ...others } = props;
|
|
33
34
|
const uuid = useId(id);
|
|
34
35
|
const [_visible, setVisibility] = useUncontrolled({
|
|
35
36
|
value: visible,
|
|
@@ -68,7 +69,7 @@ const PasswordInput = factory((_props) => {
|
|
|
68
69
|
disabled,
|
|
69
70
|
radius,
|
|
70
71
|
"aria-pressed": _visible,
|
|
71
|
-
tabIndex: -1,
|
|
72
|
+
tabIndex: visibilityToggleFocusable ? 0 : -1,
|
|
72
73
|
"aria-label": "Toggle password visibility",
|
|
73
74
|
...visibilityToggleButtonProps,
|
|
74
75
|
variant: visibilityToggleButtonProps?.variant ?? "subtle",
|
|
@@ -86,7 +87,7 @@ const PasswordInput = factory((_props) => {
|
|
|
86
87
|
},
|
|
87
88
|
onKeyDown: (event) => {
|
|
88
89
|
visibilityToggleButtonProps?.onKeyDown?.(event);
|
|
89
|
-
if (event.key === " ") {
|
|
90
|
+
if (event.key === " " || event.key === "Enter") {
|
|
90
91
|
event.preventDefault();
|
|
91
92
|
toggleVisibility();
|
|
92
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordInput.mjs","names":["classes"],"sources":["../../../src/components/PasswordInput/PasswordInput.tsx"],"sourcesContent":["import cx from 'clsx';\nimport { useId, useUncontrolled } from '@mantine/hooks';\nimport {\n BoxProps,\n createVarsResolver,\n ElementProps,\n extractStyleProps,\n factory,\n Factory,\n getSize,\n StylesApiProps,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '../../core';\nimport { ActionIcon } from '../ActionIcon';\nimport { __BaseInputProps, __InputStylesNames, Input, InputVariant } from '../Input';\nimport { InputBase } from '../InputBase';\nimport { PasswordToggleIcon } from './PasswordToggleIcon';\nimport classes from './PasswordInput.module.css';\n\nexport type PasswordInputStylesNames =\n | 'root'\n | 'visibilityToggle'\n | 'innerInput'\n | __InputStylesNames;\nexport type PasswordInputCssVariables = {\n root: '--psi-icon-size' | '--psi-button-size';\n};\n\nexport interface PasswordInputProps\n extends\n BoxProps,\n Omit<__BaseInputProps, 'pointer'>,\n StylesApiProps<PasswordInputFactory>,\n ElementProps<'input', 'size'> {\n /** A component to replace the visibility toggle icon */\n visibilityToggleIcon?: React.FC<{ reveal: boolean }>;\n\n /** Props passed down to the visibility toggle button */\n visibilityToggleButtonProps?: Record<string, any>;\n\n /** If set, the input value is visible */\n visible?: boolean;\n\n /** If set, the input value is visible by default */\n defaultVisible?: boolean;\n\n /** Called when visibility changes */\n onVisibilityChange?: (visible: boolean) => void;\n}\n\nexport type PasswordInputFactory = Factory<{\n props: PasswordInputProps;\n ref: HTMLInputElement;\n stylesNames: PasswordInputStylesNames;\n vars: PasswordInputCssVariables;\n variant: InputVariant;\n}>;\n\nconst defaultProps = {\n visibilityToggleIcon: PasswordToggleIcon,\n size: 'sm',\n} satisfies Partial<PasswordInputProps>;\n\nconst varsResolver = createVarsResolver<PasswordInputFactory>((_, { size }) => ({\n root: {\n '--psi-icon-size': getSize(size, 'psi-icon-size'),\n '--psi-button-size': getSize(size, 'psi-button-size'),\n },\n}));\n\nexport const PasswordInput = factory<PasswordInputFactory>((_props) => {\n const props = useProps(['Input', 'InputWrapper', 'PasswordInput'], defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n required,\n error,\n success,\n leftSection,\n disabled,\n id,\n variant,\n inputContainer,\n description,\n label,\n size,\n errorProps,\n successProps,\n descriptionProps,\n labelProps,\n withAsterisk,\n inputWrapperOrder,\n wrapperProps,\n radius,\n rightSection,\n rightSectionWidth,\n rightSectionPointerEvents,\n leftSectionWidth,\n visible,\n defaultVisible,\n onVisibilityChange,\n visibilityToggleIcon: VisibilityToggleIcon,\n visibilityToggleButtonProps,\n rightSectionProps,\n leftSectionProps,\n leftSectionPointerEvents,\n withErrorStyles,\n withSuccessStyles,\n mod,\n attributes,\n dir,\n ...others\n } = props;\n\n const uuid = useId(id);\n\n const [_visible, setVisibility] = useUncontrolled({\n value: visible,\n defaultValue: defaultVisible,\n finalValue: false,\n onChange: onVisibilityChange,\n });\n\n const toggleVisibility = () => setVisibility(!_visible);\n\n const getStyles = useStyles<PasswordInputFactory>({\n name: 'PasswordInput',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<PasswordInputFactory>({\n classNames,\n styles,\n props,\n });\n\n const { styleProps, rest } = extractStyleProps(others);\n const errorId = errorProps?.id || `${uuid}-error`;\n const successId = successProps?.id || `${uuid}-success`;\n const descriptionId = descriptionProps?.id || `${uuid}-description`;\n const hasError = !!error && typeof error !== 'boolean';\n const hasSuccess = !!success && typeof success !== 'boolean';\n const hasDescription = !!description;\n const _describedBy = `${hasError ? errorId : ''} ${hasSuccess && !hasError ? successId : ''} ${hasDescription ? descriptionId : ''}`;\n const describedBy = _describedBy.trim().length > 0 ? _describedBy.trim() : undefined;\n\n const visibilityToggleButton = (\n <ActionIcon<'button'>\n {...getStyles('visibilityToggle')}\n disabled={disabled}\n radius={radius}\n aria-pressed={_visible}\n tabIndex={-1}\n aria-label=\"Toggle password visibility\"\n {...visibilityToggleButtonProps}\n variant={visibilityToggleButtonProps?.variant ?? 'subtle'}\n color=\"gray\"\n unstyled={unstyled}\n onTouchEnd={(event) => {\n event.preventDefault();\n visibilityToggleButtonProps?.onTouchEnd?.(event);\n toggleVisibility();\n }}\n onMouseDown={(event) => {\n event.preventDefault();\n visibilityToggleButtonProps?.onMouseDown?.(event);\n toggleVisibility();\n }}\n onKeyDown={(event) => {\n visibilityToggleButtonProps?.onKeyDown?.(event);\n if (event.key === ' ') {\n event.preventDefault();\n toggleVisibility();\n }\n }}\n >\n <VisibilityToggleIcon reveal={_visible} />\n </ActionIcon>\n );\n\n return (\n <Input.Wrapper\n required={required}\n id={uuid}\n label={label}\n error={error}\n success={success}\n description={description}\n size={size}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n __staticSelector=\"PasswordInput\"\n __stylesApiProps={props}\n unstyled={unstyled}\n withAsterisk={withAsterisk}\n inputWrapperOrder={inputWrapperOrder}\n inputContainer={inputContainer}\n variant={variant}\n labelProps={{ ...labelProps, htmlFor: uuid }}\n descriptionProps={{ ...descriptionProps, id: descriptionId }}\n errorProps={{ ...errorProps, id: errorId }}\n successProps={{ ...successProps, id: successId }}\n mod={mod}\n attributes={attributes}\n {...getStyles('root')}\n {...styleProps}\n {...wrapperProps}\n >\n <Input\n component=\"div\"\n dir={dir}\n error={error}\n success={success}\n leftSection={leftSection}\n size={size}\n classNames={{ ...resolvedClassNames, input: cx(classes.input, resolvedClassNames?.input) }}\n styles={resolvedStyles}\n radius={radius}\n disabled={disabled}\n __staticSelector=\"PasswordInput\"\n __stylesApiProps={props}\n rightSectionWidth={rightSectionWidth}\n rightSection={rightSection ?? visibilityToggleButton}\n variant={variant}\n unstyled={unstyled}\n leftSectionWidth={leftSectionWidth}\n rightSectionPointerEvents={rightSectionPointerEvents || 'all'}\n rightSectionProps={rightSectionProps}\n leftSectionProps={leftSectionProps}\n leftSectionPointerEvents={leftSectionPointerEvents}\n withAria={false}\n withErrorStyles={withErrorStyles}\n withSuccessStyles={withSuccessStyles}\n attributes={attributes}\n >\n <input\n required={required}\n data-invalid={!!error || undefined}\n data-with-left-section={!!leftSection || undefined}\n {...getStyles('innerInput')}\n disabled={disabled}\n id={uuid}\n dir={dir}\n {...rest}\n aria-describedby={describedBy}\n autoComplete={rest.autoComplete || 'off'}\n type={_visible ? 'text' : 'password'}\n />\n </Input>\n </Input.Wrapper>\n );\n});\n\nPasswordInput.classes = { ...InputBase.classes, ...classes };\nPasswordInput.varsResolver = varsResolver;\nPasswordInput.displayName = '@mantine/core/PasswordInput';\n\nexport namespace PasswordInput {\n export type Props = PasswordInputProps;\n export type StylesNames = PasswordInputStylesNames;\n export type CssVariables = PasswordInputCssVariables;\n export type Factory = Pas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cAAc,gBAAgB;GACrB;GACC;GACQ;GAClB,2BAA2B,6BAA6B;GACrC;GACD;GACQ;GAC1B,UAAU;GACO;GACE;GACP;aAEZ,oBAAC,SAAD;IACY;IACV,gBAAc,CAAC,CAAC,SAAS,KAAA;IACzB,0BAAwB,CAAC,CAAC,eAAe,KAAA;IACzC,GAAI,UAAU,YAAY;IAChB;IACV,IAAI;IACC;IACL,GAAI;IACJ,oBAAkB;IAClB,cAAc,KAAK,gBAAgB;IACnC,MAAM,WAAW,SAAS;GAC3B,CAAA;EACI,CAAA;CACM,CAAA;AAEnB,CAAC;AAED,cAAc,UAAU;CAAE,GAAG,UAAU;CAAS,GAAGA;AAAQ;AAC3D,cAAc,eAAe;AAC7B,cAAc,cAAc"}
|
|
1
|
+
{"version":3,"file":"PasswordInput.mjs","names":["classes"],"sources":["../../../src/components/PasswordInput/PasswordInput.tsx"],"sourcesContent":["import cx from 'clsx';\nimport { useId, useUncontrolled } from '@mantine/hooks';\nimport {\n BoxProps,\n createVarsResolver,\n ElementProps,\n extractStyleProps,\n factory,\n Factory,\n getSize,\n StylesApiProps,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '../../core';\nimport { ActionIcon } from '../ActionIcon';\nimport { __BaseInputProps, __InputStylesNames, Input, InputVariant } from '../Input';\nimport { InputBase } from '../InputBase';\nimport { PasswordToggleIcon } from './PasswordToggleIcon';\nimport classes from './PasswordInput.module.css';\n\nexport type PasswordInputStylesNames =\n | 'root'\n | 'visibilityToggle'\n | 'innerInput'\n | __InputStylesNames;\nexport type PasswordInputCssVariables = {\n root: '--psi-icon-size' | '--psi-button-size';\n};\n\nexport interface PasswordInputProps\n extends\n BoxProps,\n Omit<__BaseInputProps, 'pointer'>,\n StylesApiProps<PasswordInputFactory>,\n ElementProps<'input', 'size'> {\n /** A component to replace the visibility toggle icon */\n visibilityToggleIcon?: React.FC<{ reveal: boolean }>;\n\n /** Props passed down to the visibility toggle button */\n visibilityToggleButtonProps?: Record<string, any>;\n\n /** If set, the visibility toggle button is focusable with keyboard @default `false` */\n visibilityToggleFocusable?: boolean;\n\n /** If set, the input value is visible */\n visible?: boolean;\n\n /** If set, the input value is visible by default */\n defaultVisible?: boolean;\n\n /** Called when visibility changes */\n onVisibilityChange?: (visible: boolean) => void;\n}\n\nexport type PasswordInputFactory = Factory<{\n props: PasswordInputProps;\n ref: HTMLInputElement;\n stylesNames: PasswordInputStylesNames;\n vars: PasswordInputCssVariables;\n variant: InputVariant;\n}>;\n\nconst defaultProps = {\n visibilityToggleIcon: PasswordToggleIcon,\n visibilityToggleFocusable: false,\n size: 'sm',\n} satisfies Partial<PasswordInputProps>;\n\nconst varsResolver = createVarsResolver<PasswordInputFactory>((_, { size }) => ({\n root: {\n '--psi-icon-size': getSize(size, 'psi-icon-size'),\n '--psi-button-size': getSize(size, 'psi-button-size'),\n },\n}));\n\nexport const PasswordInput = factory<PasswordInputFactory>((_props) => {\n const props = useProps(['Input', 'InputWrapper', 'PasswordInput'], defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n required,\n error,\n success,\n leftSection,\n disabled,\n id,\n variant,\n inputContainer,\n description,\n label,\n size,\n errorProps,\n successProps,\n descriptionProps,\n labelProps,\n withAsterisk,\n inputWrapperOrder,\n wrapperProps,\n radius,\n rightSection,\n rightSectionWidth,\n rightSectionPointerEvents,\n leftSectionWidth,\n visible,\n defaultVisible,\n onVisibilityChange,\n visibilityToggleIcon: VisibilityToggleIcon,\n visibilityToggleButtonProps,\n visibilityToggleFocusable,\n rightSectionProps,\n leftSectionProps,\n leftSectionPointerEvents,\n withErrorStyles,\n withSuccessStyles,\n mod,\n attributes,\n dir,\n ...others\n } = props;\n\n const uuid = useId(id);\n\n const [_visible, setVisibility] = useUncontrolled({\n value: visible,\n defaultValue: defaultVisible,\n finalValue: false,\n onChange: onVisibilityChange,\n });\n\n const toggleVisibility = () => setVisibility(!_visible);\n\n const getStyles = useStyles<PasswordInputFactory>({\n name: 'PasswordInput',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<PasswordInputFactory>({\n classNames,\n styles,\n props,\n });\n\n const { styleProps, rest } = extractStyleProps(others);\n const errorId = errorProps?.id || `${uuid}-error`;\n const successId = successProps?.id || `${uuid}-success`;\n const descriptionId = descriptionProps?.id || `${uuid}-description`;\n const hasError = !!error && typeof error !== 'boolean';\n const hasSuccess = !!success && typeof success !== 'boolean';\n const hasDescription = !!description;\n const _describedBy = `${hasError ? errorId : ''} ${hasSuccess && !hasError ? successId : ''} ${hasDescription ? descriptionId : ''}`;\n const describedBy = _describedBy.trim().length > 0 ? _describedBy.trim() : undefined;\n\n const visibilityToggleButton = (\n <ActionIcon<'button'>\n {...getStyles('visibilityToggle')}\n disabled={disabled}\n radius={radius}\n aria-pressed={_visible}\n tabIndex={visibilityToggleFocusable ? 0 : -1}\n aria-label=\"Toggle password visibility\"\n {...visibilityToggleButtonProps}\n variant={visibilityToggleButtonProps?.variant ?? 'subtle'}\n color=\"gray\"\n unstyled={unstyled}\n onTouchEnd={(event) => {\n event.preventDefault();\n visibilityToggleButtonProps?.onTouchEnd?.(event);\n toggleVisibility();\n }}\n onMouseDown={(event) => {\n event.preventDefault();\n visibilityToggleButtonProps?.onMouseDown?.(event);\n toggleVisibility();\n }}\n onKeyDown={(event) => {\n visibilityToggleButtonProps?.onKeyDown?.(event);\n if (event.key === ' ' || event.key === 'Enter') {\n event.preventDefault();\n toggleVisibility();\n }\n }}\n >\n <VisibilityToggleIcon reveal={_visible} />\n </ActionIcon>\n );\n\n return (\n <Input.Wrapper\n required={required}\n id={uuid}\n label={label}\n error={error}\n success={success}\n description={description}\n size={size}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n __staticSelector=\"PasswordInput\"\n __stylesApiProps={props}\n unstyled={unstyled}\n withAsterisk={withAsterisk}\n inputWrapperOrder={inputWrapperOrder}\n inputContainer={inputContainer}\n variant={variant}\n labelProps={{ ...labelProps, htmlFor: uuid }}\n descriptionProps={{ ...descriptionProps, id: descriptionId }}\n errorProps={{ ...errorProps, id: errorId }}\n successProps={{ ...successProps, id: successId }}\n mod={mod}\n attributes={attributes}\n {...getStyles('root')}\n {...styleProps}\n {...wrapperProps}\n >\n <Input\n component=\"div\"\n dir={dir}\n error={error}\n success={success}\n leftSection={leftSection}\n size={size}\n classNames={{ ...resolvedClassNames, input: cx(classes.input, resolvedClassNames?.input) }}\n styles={resolvedStyles}\n radius={radius}\n disabled={disabled}\n __staticSelector=\"PasswordInput\"\n __stylesApiProps={props}\n rightSectionWidth={rightSectionWidth}\n rightSection={rightSection ?? visibilityToggleButton}\n variant={variant}\n unstyled={unstyled}\n leftSectionWidth={leftSectionWidth}\n rightSectionPointerEvents={rightSectionPointerEvents || 'all'}\n rightSectionProps={rightSectionProps}\n leftSectionProps={leftSectionProps}\n leftSectionPointerEvents={leftSectionPointerEvents}\n withAria={false}\n withErrorStyles={withErrorStyles}\n withSuccessStyles={withSuccessStyles}\n attributes={attributes}\n >\n <input\n required={required}\n data-invalid={!!error || undefined}\n data-with-left-section={!!leftSection || undefined}\n {...getStyles('innerInput')}\n disabled={disabled}\n id={uuid}\n dir={dir}\n {...rest}\n aria-describedby={describedBy}\n autoComplete={rest.autoComplete || 'off'}\n type={_visible ? 'text' : 'password'}\n />\n </Input>\n </Input.Wrapper>\n );\n});\n\nPasswordInput.classes = { ...InputBase.classes, ...classes };\nPasswordInput.varsResolver = varsResolver;\nPasswordInput.displayName = '@mantine/core/PasswordInput';\n\nexport namespace PasswordInput {\n export type Props = PasswordInputProps;\n export type StylesNames = PasswordInputStylesNames;\n export type CssVariables = PasswordInputCssVariables;\n export type Factory = PasswordInputFactory;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA+DA,MAAM,eAAe;CACnB,sBAAsB;CACtB,2BAA2B;CAC3B,MAAM;AACR;AAEA,MAAM,eAAe,oBAA0C,GAAG,EAA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;GACE;GACP;aAEZ,oBAAC,SAAD;IACY;IACV,gBAAc,CAAC,CAAC,SAAS,KAAA;IACzB,0BAAwB,CAAC,CAAC,eAAe,KAAA;IACzC,GAAI,UAAU,YAAY;IAChB;IACV,IAAI;IACC;IACL,GAAI;IACJ,oBAAkB;IAClB,cAAc,KAAK,gBAAgB;IACnC,MAAM,WAAW,SAAS;GAC3B,CAAA;EACI,CAAA;CACM,CAAA;AAEnB,CAAC;AAED,cAAc,UAAU;CAAE,GAAG,UAAU;CAAS,GAAGA;AAAQ;AAC3D,cAAc,eAAe;AAC7B,cAAc,cAAc"}
|
|
@@ -64,7 +64,7 @@ const varsResolver = createVarsResolver((theme, { radius, color, variant, autoCo
|
|
|
64
64
|
});
|
|
65
65
|
const Tooltip = factory((_props) => {
|
|
66
66
|
const props = useProps("Tooltip", defaultProps, _props);
|
|
67
|
-
const { children, position, refProp, label, openDelay, closeDelay, onPositionChange, opened, defaultOpened, withinPortal, radius, color, classNames, styles, unstyled, style, className, withArrow, arrowSize, arrowOffset, arrowRadius, arrowPosition, offset, transitionProps, multiline, events, zIndex, disabled, onClick, onMouseEnter, onMouseLeave, inline, variant, keepMounted, vars, portalProps, mod, floatingStrategy, middlewares, autoContrast, attributes, target, ref, ...others } = props;
|
|
67
|
+
const { children, position, refProp, label, openDelay, closeDelay, onPositionChange, opened, defaultOpened, withinPortal, radius, color, classNames, styles, unstyled, style, className, withArrow, arrowSize, arrowOffset, arrowRadius, arrowPosition, offset, transitionProps, multiline, events, interactive, zIndex, disabled, onClick, onMouseEnter, onMouseLeave, inline, variant, keepMounted, vars, portalProps, mod, floatingStrategy, middlewares, autoContrast, attributes, target, ref, ...others } = props;
|
|
68
68
|
const { dir } = useDirection();
|
|
69
69
|
const arrowRef = useRef(null);
|
|
70
70
|
const tooltip = useTooltip({
|
|
@@ -75,6 +75,7 @@ const Tooltip = factory((_props) => {
|
|
|
75
75
|
opened,
|
|
76
76
|
defaultOpened,
|
|
77
77
|
events,
|
|
78
|
+
interactive,
|
|
78
79
|
arrowRef,
|
|
79
80
|
arrowOffset,
|
|
80
81
|
offset: typeof offset === "number" ? offset + (withArrow ? arrowSize / 2 : 0) : offset,
|
|
@@ -103,6 +104,7 @@ const Tooltip = factory((_props) => {
|
|
|
103
104
|
const child = getSingleElementChild(children);
|
|
104
105
|
if (!target && !child) throw new Error("[@mantine/core] Tooltip component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported");
|
|
105
106
|
const tooltipStyles = getStyles("tooltip");
|
|
107
|
+
const interactiveMod = interactive && !disabled && !!tooltip.opened;
|
|
106
108
|
const mergeStyles = arrowPosition === "merge" && withArrow ? getArrowMergeDropdownStyles({
|
|
107
109
|
position: tooltip.placement,
|
|
108
110
|
dir
|
|
@@ -124,7 +126,10 @@ const Tooltip = factory((_props) => {
|
|
|
124
126
|
...others,
|
|
125
127
|
"data-fixed": floatingStrategy === "fixed" || void 0,
|
|
126
128
|
variant,
|
|
127
|
-
mod: [{
|
|
129
|
+
mod: [{
|
|
130
|
+
multiline,
|
|
131
|
+
interactive: interactiveMod
|
|
132
|
+
}, mod],
|
|
128
133
|
...tooltipStyles,
|
|
129
134
|
...tooltip.getFloatingProps({
|
|
130
135
|
ref: tooltip.floating,
|
|
@@ -172,7 +177,10 @@ const Tooltip = factory((_props) => {
|
|
|
172
177
|
...others,
|
|
173
178
|
"data-fixed": floatingStrategy === "fixed" || void 0,
|
|
174
179
|
variant,
|
|
175
|
-
mod: [{
|
|
180
|
+
mod: [{
|
|
181
|
+
multiline,
|
|
182
|
+
interactive: interactiveMod
|
|
183
|
+
}, mod],
|
|
176
184
|
...tooltip.getFloatingProps({
|
|
177
185
|
ref: tooltip.floating,
|
|
178
186
|
className: getStyles("tooltip").className,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.mjs","names":["classes"],"sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import { cloneElement, useEffect, useRef } from 'react';\nimport cx from 'clsx';\nimport { useMergedRef } from '@mantine/hooks';\nimport {\n Box,\n createVarsResolver,\n factory,\n Factory,\n getDefaultZIndex,\n getRadius,\n getRefProp,\n getSingleElementChild,\n useDirection,\n useProps,\n useStyles,\n} from '../../core';\nimport {\n ArrowPosition,\n FloatingArrow,\n FloatingAxesOffsets,\n FloatingPosition,\n FloatingStrategy,\n getArrowMergeDropdownStyles,\n getFloatingPosition,\n} from '../../utils/Floating';\nimport { OptionalPortal } from '../Portal';\nimport { getTransitionProps, Transition, TransitionOverride } from '../Transition';\nimport { TooltipBaseProps, TooltipCssVariables, TooltipStylesNames } from './Tooltip.types';\nimport { TooltipFloating, type TooltipFloatingProps } from './TooltipFloating/TooltipFloating';\nimport {\n TooltipGroup,\n type TooltipGroupProps,\n type TooltipGroupContextValue,\n} from './TooltipGroup/TooltipGroup';\nimport { useTooltip } from './use-tooltip';\nimport classes from './Tooltip.module.css';\nexport interface TooltipProps extends TooltipBaseProps {\n /** Called when tooltip position changes */\n onPositionChange?: (position: FloatingPosition) => void;\n\n /** Open delay in ms */\n openDelay?: number;\n\n /** Close delay in ms @default 0 */\n closeDelay?: number;\n\n /** Controlled opened state */\n opened?: boolean;\n\n /** Uncontrolled tooltip initial opened state */\n defaultOpened?: boolean;\n\n /** Space between target element and tooltip in px @default 5 */\n offset?: number | FloatingAxesOffsets;\n\n /** If set, the tooltip has an arrow @default false */\n withArrow?: boolean;\n\n /** Arrow size in px @default 4 */\n arrowSize?: number;\n\n /** Arrow offset in px @default 5 */\n arrowOffset?: number;\n\n /** Arrow `border-radius` in px @default 0 */\n arrowRadius?: number;\n\n /** Arrow position relative to the tooltip @default side */\n arrowPosition?: ArrowPosition;\n\n /** Props passed down to the `Transition` component that used to animate tooltip presence, use to configure duration and animation type @default { duration: 100, transition: 'fade' } */\n transitionProps?: TransitionOverride;\n\n /** Determines which events will be used to show tooltip @default { hover: true, focus: false, touch: false } */\n events?: { hover: boolean; focus: boolean; touch: boolean };\n\n /** Must be set if the tooltip target is an inline element */\n inline?: boolean;\n\n /** If set, the tooltip is not unmounted from the DOM when hidden, `display: none` styles are applied instead */\n keepMounted?: boolean;\n\n /** Changes floating ui [position strategy](https://floating-ui.com/docs/usefloating#strategy) @default 'absolute' */\n floatingStrategy?: FloatingStrategy;\n\n /** If set, adjusts text color based on background color for `filled` variant */\n autoContrast?: boolean;\n\n /** Selector, ref of an element or element itself that should be used for positioning */\n target?: React.RefObject<HTMLElement | null> | HTMLElement | null | string;\n}\n\nexport type TooltipFactory = Factory<{\n props: TooltipProps;\n ref: HTMLDivElement;\n stylesNames: TooltipStylesNames;\n vars: TooltipCssVariables;\n staticComponents: {\n Floating: typeof TooltipFloating;\n Group: typeof TooltipGroup;\n };\n}>;\n\nconst defaultProps = {\n position: 'top',\n refProp: 'ref',\n withinPortal: true,\n arrowSize: 4,\n arrowOffset: 5,\n arrowRadius: 0,\n arrowPosition: 'side',\n offset: 5,\n transitionProps: { duration: 100, transition: 'fade' },\n events: { hover: true, focus: false, touch: false },\n zIndex: getDefaultZIndex('popover'),\n middlewares: { flip: true, shift: true, inline: false },\n} satisfies Partial<TooltipProps>;\n\nconst varsResolver = createVarsResolver<TooltipFactory>(\n (theme, { radius, color, variant, autoContrast }) => {\n const colors = theme.variantColorResolver({\n theme,\n color: color || theme.primaryColor,\n autoContrast,\n variant: variant || 'filled',\n });\n\n return {\n tooltip: {\n '--tooltip-radius': radius === undefined ? undefined : getRadius(radius),\n '--tooltip-bg': color ? colors.background : undefined,\n '--tooltip-color': color ? colors.color : undefined,\n },\n };\n }\n);\n\nexport const Tooltip = factory<TooltipFactory>((_props) => {\n const props = useProps('Tooltip', defaultProps, _props);\n const {\n children,\n position,\n refProp,\n label,\n openDelay,\n closeDelay,\n onPositionChange,\n opened,\n defaultOpened,\n withinPortal,\n radius,\n color,\n classNames,\n styles,\n unstyled,\n style,\n className,\n withArrow,\n arrowSize,\n arrowOffset,\n arrowRadius,\n arrowPosition,\n offset,\n transitionProps,\n multiline,\n events,\n zIndex,\n disabled,\n onClick,\n onMouseEnter,\n onMouseLeave,\n inline,\n variant,\n keepMounted,\n vars,\n portalProps,\n mod,\n floatingStrategy,\n middlewares,\n autoContrast,\n attributes,\n target,\n ref,\n ...others\n } = props;\n\n const { dir } = useDirection();\n const arrowRef = useRef<HTMLDivElement>(null);\n\n const tooltip = useTooltip({\n position: getFloatingPosition(dir, position),\n closeDelay,\n openDelay,\n onPositionChange,\n opened,\n defaultOpened,\n events,\n arrowRef,\n arrowOffset,\n offset: typeof offset === 'number' ? offset + (withArrow ? arrowSize / 2 : 0) : offset,\n inline,\n strategy: floatingStrategy,\n middlewares,\n });\n\n useEffect(() => {\n const targetNode =\n target instanceof HTMLElement\n ? target\n : typeof target === 'string'\n ? document.querySelector(target)\n : target?.current || null;\n\n if (targetNode) {\n tooltip.reference(targetNode);\n }\n }, [target, tooltip]);\n\n const getStyles = useStyles<TooltipFactory>({\n name: 'Tooltip',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'tooltip',\n vars,\n varsResolver,\n });\n\n const child = getSingleElementChild(children);\n if (!target && !child) {\n throw new Error(\n '[@mantine/core] Tooltip component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported'\n );\n }\n\n const tooltipStyles = getStyles('tooltip');\n const mergeStyles =\n arrowPosition === 'merge' && withArrow\n ? getArrowMergeDropdownStyles({ position: tooltip.placement, dir })\n : undefined;\n\n if (target) {\n const transition = getTransitionProps(transitionProps, { duration: 100, transition: 'fade' });\n return (\n <>\n <OptionalPortal {...portalProps} withinPortal={withinPortal}>\n <Transition\n {...transition}\n keepMounted={keepMounted}\n mounted={!disabled && !!tooltip.opened}\n duration={tooltip.isGroupPhase ? 10 : transition.duration}\n >\n {(transitionStyles) => (\n <Box\n {...others}\n data-fixed={floatingStrategy === 'fixed' || undefined}\n variant={variant}\n mod={[{ multiline }, mod]}\n {...tooltipStyles}\n {...tooltip.getFloatingProps({\n ref: tooltip.floating,\n className: tooltipStyles.className,\n style: {\n ...tooltipStyles.style,\n ...transitionStyles,\n ...mergeStyles,\n zIndex: zIndex as React.CSSProperties['zIndex'],\n top: tooltip.y ?? 0,\n left: tooltip.x ?? 0,\n },\n })}\n >\n {label}\n <FloatingArrow\n ref={arrowRef}\n arrowX={tooltip.arrowX}\n arrowY={tooltip.arrowY}\n visible={withArrow}\n position={tooltip.placement}\n arrowSize={arrowSize!}\n arrowOffset={arrowOffset!}\n arrowRadius={arrowRadius!}\n arrowPosition={arrowPosition!}\n {...getStyles('arrow')}\n />\n </Box>\n )}\n </Transition>\n </OptionalPortal>\n </>\n );\n }\n\n // fallback to children-based approach\n const childProps = child!.props as any;\n const targetRef = useMergedRef(tooltip.reference, getRefProp(child), ref);\n const transition = getTransitionProps(transitionProps, { duration: 100, transition: 'fade' });\n\n return (\n <>\n <OptionalPortal {...portalProps} withinPortal={withinPortal}>\n <Transition\n {...transition}\n keepMounted={keepMounted}\n mounted={!disabled && !!tooltip.opened}\n duration={tooltip.isGroupPhase ? 10 : transition.duration}\n >\n {(transitionStyles) => (\n <Box\n {...others}\n data-fixed={floatingStrategy === 'fixed' || undefined}\n variant={variant}\n mod={[{ multiline }, mod]}\n {...tooltip.getFloatingProps({\n ref: tooltip.floating,\n className: getStyles('tooltip').className,\n style: {\n ...getStyles('tooltip').style,\n ...transitionStyles,\n ...mergeStyles,\n zIndex: zIndex as React.CSSProperties['zIndex'],\n top: tooltip.y ?? 0,\n left: tooltip.x ?? 0,\n },\n })}\n >\n {label}\n <FloatingArrow\n ref={arrowRef}\n arrowX={tooltip.arrowX}\n arrowY={tooltip.arrowY}\n visible={withArrow}\n position={tooltip.placement}\n arrowSize={arrowSize}\n arrowOffset={arrowOffset}\n arrowRadius={arrowRadius}\n arrowPosition={arrowPosition}\n {...getStyles('arrow')}\n />\n </Box>\n )}\n </Transition>\n </OptionalPortal>\n\n {cloneElement(\n child!,\n tooltip.getReferenceProps({\n onClick,\n onMouseEnter,\n onMouseLeave,\n onMouseMove: props.onMouseMove,\n onPointerDown: props.onPointerDown,\n onPointerEnter: props.onPointerEnter,\n ...childProps,\n className: cx(className, childProps.className),\n [refProp]: targetRef,\n })\n )}\n </>\n );\n});\n\nTooltip.classes = classes;\nTooltip.varsResolver = varsResolver;\nTooltip.displayName = '@mantine/core/Tooltip';\nTooltip.Floating = TooltipFloating;\nTooltip.Group = TooltipGroup;\n\nexport namespace Tooltip {\n export type Props = TooltipProps;\n export type Factory = TooltipFactory;\n export type CssVariables = TooltipCssVariables;\n export type StylesNames = TooltipStylesNames;\n\n export namespace Group {\n export type Props = TooltipGroupProps;\n export type ContextValue = TooltipGroupContextValue;\n }\n\n export namespace Floating {\n export type Props = TooltipFloatingProps;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,MAAM,eAAe;CACnB,UAAU;CACV,SAAS;CACT,cAAc;CACd,WAAW;CACX,aAAa;CACb,aAAa;CACb,eAAe;CACf,QAAQ;CACR,iBAAiB;EAAE,UAAU;EAAK,YAAY;CAAO;CACrD,QAAQ;EAAE,OAAO;EAAM,OAAO;EAAO,OAAO;CAAM;CAClD,QAAQ,iBAAiB,SAAS;CAClC,aAAa;EAAE,MAAM;EAAM,OAAO;EAAM,QAAQ;CAAM;AACxD;AAEA,MAAM,eAAe,oBAClB,OAAO,EAAE,QAAQ,OAAO,SAAS,mBAAmB;CACnD,MAAM,SAAS,MAAM,qBAAqB;EACxC;EACA,OAAO,SAAS,MAAM;EACtB;EACA,SAAS,WAAW;CACtB,CAAC;CAED,OAAO,EACL,SAAS;EACP,oBAAoB,WAAW,KAAA,IAAY,KAAA,IAAY,UAAU,MAAM;EACvE,gBAAgB,QAAQ,OAAO,aAAa,KAAA;EAC5C,mBAAmB,QAAQ,OAAO,QAAQ,KAAA;CAC5C,EACF;AACF,CACF;AAEA,MAAa,UAAU,SAAyB,WAAW;CACzD,MAAM,QAAQ,SAAS,WAAW,cAAc,MAAM;CACtD,MAAM,EACJ,UACA,UAC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AAK;KACrB;IACF,CAAC;cAhBH,CAkBG,OACD,oBAAC,eAAD;KACE,KAAK;KACL,QAAQ,QAAQ;KAChB,QAAQ,QAAQ;KAChB,SAAS;KACT,UAAU,QAAQ;KACP;KACE;KACA;KACE;KACf,GAAI,UAAU,OAAO;IACtB,CAAA,CACE;;EAEG,CAAA;CACE,CAAA,GAEf,aACC,OACA,QAAQ,kBAAkB;EACxB;EACA;EACA;EACA,aAAa,MAAM;EACnB,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACtB,GAAG;EACH,WAAW,GAAG,WAAW,WAAW,SAAS;GAC5C,UAAU;CACb,CAAC,CACH,CACA,EAAA,CAAA;AAEN,CAAC;AAED,QAAQ,UAAUA;AAClB,QAAQ,eAAe;AACvB,QAAQ,cAAc;AACtB,QAAQ,WAAW;AACnB,QAAQ,QAAQ"}
|
|
1
|
+
{"version":3,"file":"Tooltip.mjs","names":["classes"],"sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import { cloneElement, useEffect, useRef } from 'react';\nimport cx from 'clsx';\nimport { useMergedRef } from '@mantine/hooks';\nimport {\n Box,\n createVarsResolver,\n factory,\n Factory,\n getDefaultZIndex,\n getRadius,\n getRefProp,\n getSingleElementChild,\n useDirection,\n useProps,\n useStyles,\n} from '../../core';\nimport {\n ArrowPosition,\n FloatingArrow,\n FloatingAxesOffsets,\n FloatingPosition,\n FloatingStrategy,\n getArrowMergeDropdownStyles,\n getFloatingPosition,\n} from '../../utils/Floating';\nimport { OptionalPortal } from '../Portal';\nimport { getTransitionProps, Transition, TransitionOverride } from '../Transition';\nimport { TooltipBaseProps, TooltipCssVariables, TooltipStylesNames } from './Tooltip.types';\nimport { TooltipFloating, type TooltipFloatingProps } from './TooltipFloating/TooltipFloating';\nimport {\n TooltipGroup,\n type TooltipGroupProps,\n type TooltipGroupContextValue,\n} from './TooltipGroup/TooltipGroup';\nimport { useTooltip } from './use-tooltip';\nimport classes from './Tooltip.module.css';\nexport interface TooltipProps extends TooltipBaseProps {\n /** Called when tooltip position changes */\n onPositionChange?: (position: FloatingPosition) => void;\n\n /** Open delay in ms */\n openDelay?: number;\n\n /** Close delay in ms @default 0 */\n closeDelay?: number;\n\n /** Controlled opened state */\n opened?: boolean;\n\n /** Uncontrolled tooltip initial opened state */\n defaultOpened?: boolean;\n\n /** Space between target element and tooltip in px @default 5 */\n offset?: number | FloatingAxesOffsets;\n\n /** If set, the tooltip has an arrow @default false */\n withArrow?: boolean;\n\n /** Arrow size in px @default 4 */\n arrowSize?: number;\n\n /** Arrow offset in px @default 5 */\n arrowOffset?: number;\n\n /** Arrow `border-radius` in px @default 0 */\n arrowRadius?: number;\n\n /** Arrow position relative to the tooltip @default side */\n arrowPosition?: ArrowPosition;\n\n /** Props passed down to the `Transition` component that used to animate tooltip presence, use to configure duration and animation type @default { duration: 100, transition: 'fade' } */\n transitionProps?: TransitionOverride;\n\n /** Determines which events will be used to show tooltip @default { hover: true, focus: false, touch: false } */\n events?: { hover: boolean; focus: boolean; touch: boolean };\n\n /** If set, the tooltip stays open while the pointer moves from the target to the tooltip and remains over it. Required by [WCAG 1.4.13](https://www.w3.org/WAI/WCAG21/Understanding/content-on-hover-or-focus.html) if the tooltip contains interactive content. Note that an interactive tooltip intercepts pointer events of the content it overlaps @default false */\n interactive?: boolean;\n\n /** Must be set if the tooltip target is an inline element */\n inline?: boolean;\n\n /** If set, the tooltip is not unmounted from the DOM when hidden, `display: none` styles are applied instead */\n keepMounted?: boolean;\n\n /** Changes floating ui [position strategy](https://floating-ui.com/docs/usefloating#strategy) @default 'absolute' */\n floatingStrategy?: FloatingStrategy;\n\n /** If set, adjusts text color based on background color for `filled` variant */\n autoContrast?: boolean;\n\n /** Selector, ref of an element or element itself that should be used for positioning */\n target?: React.RefObject<HTMLElement | null> | HTMLElement | null | string;\n}\n\nexport type TooltipFactory = Factory<{\n props: TooltipProps;\n ref: HTMLDivElement;\n stylesNames: TooltipStylesNames;\n vars: TooltipCssVariables;\n staticComponents: {\n Floating: typeof TooltipFloating;\n Group: typeof TooltipGroup;\n };\n}>;\n\nconst defaultProps = {\n position: 'top',\n refProp: 'ref',\n withinPortal: true,\n arrowSize: 4,\n arrowOffset: 5,\n arrowRadius: 0,\n arrowPosition: 'side',\n offset: 5,\n transitionProps: { duration: 100, transition: 'fade' },\n events: { hover: true, focus: false, touch: false },\n zIndex: getDefaultZIndex('popover'),\n middlewares: { flip: true, shift: true, inline: false },\n} satisfies Partial<TooltipProps>;\n\nconst varsResolver = createVarsResolver<TooltipFactory>(\n (theme, { radius, color, variant, autoContrast }) => {\n const colors = theme.variantColorResolver({\n theme,\n color: color || theme.primaryColor,\n autoContrast,\n variant: variant || 'filled',\n });\n\n return {\n tooltip: {\n '--tooltip-radius': radius === undefined ? undefined : getRadius(radius),\n '--tooltip-bg': color ? colors.background : undefined,\n '--tooltip-color': color ? colors.color : undefined,\n },\n };\n }\n);\n\nexport const Tooltip = factory<TooltipFactory>((_props) => {\n const props = useProps('Tooltip', defaultProps, _props);\n const {\n children,\n position,\n refProp,\n label,\n openDelay,\n closeDelay,\n onPositionChange,\n opened,\n defaultOpened,\n withinPortal,\n radius,\n color,\n classNames,\n styles,\n unstyled,\n style,\n className,\n withArrow,\n arrowSize,\n arrowOffset,\n arrowRadius,\n arrowPosition,\n offset,\n transitionProps,\n multiline,\n events,\n interactive,\n zIndex,\n disabled,\n onClick,\n onMouseEnter,\n onMouseLeave,\n inline,\n variant,\n keepMounted,\n vars,\n portalProps,\n mod,\n floatingStrategy,\n middlewares,\n autoContrast,\n attributes,\n target,\n ref,\n ...others\n } = props;\n\n const { dir } = useDirection();\n const arrowRef = useRef<HTMLDivElement>(null);\n\n const tooltip = useTooltip({\n position: getFloatingPosition(dir, position),\n closeDelay,\n openDelay,\n onPositionChange,\n opened,\n defaultOpened,\n events,\n interactive,\n arrowRef,\n arrowOffset,\n offset: typeof offset === 'number' ? offset + (withArrow ? arrowSize / 2 : 0) : offset,\n inline,\n strategy: floatingStrategy,\n middlewares,\n });\n\n useEffect(() => {\n const targetNode =\n target instanceof HTMLElement\n ? target\n : typeof target === 'string'\n ? document.querySelector(target)\n : target?.current || null;\n\n if (targetNode) {\n tooltip.reference(targetNode);\n }\n }, [target, tooltip]);\n\n const getStyles = useStyles<TooltipFactory>({\n name: 'Tooltip',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'tooltip',\n vars,\n varsResolver,\n });\n\n const child = getSingleElementChild(children);\n if (!target && !child) {\n throw new Error(\n '[@mantine/core] Tooltip component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported'\n );\n }\n\n const tooltipStyles = getStyles('tooltip');\n const interactiveMod = interactive && !disabled && !!tooltip.opened;\n const mergeStyles =\n arrowPosition === 'merge' && withArrow\n ? getArrowMergeDropdownStyles({ position: tooltip.placement, dir })\n : undefined;\n\n if (target) {\n const transition = getTransitionProps(transitionProps, { duration: 100, transition: 'fade' });\n return (\n <>\n <OptionalPortal {...portalProps} withinPortal={withinPortal}>\n <Transition\n {...transition}\n keepMounted={keepMounted}\n mounted={!disabled && !!tooltip.opened}\n duration={tooltip.isGroupPhase ? 10 : transition.duration}\n >\n {(transitionStyles) => (\n <Box\n {...others}\n data-fixed={floatingStrategy === 'fixed' || undefined}\n variant={variant}\n mod={[{ multiline, interactive: interactiveMod }, mod]}\n {...tooltipStyles}\n {...tooltip.getFloatingProps({\n ref: tooltip.floating,\n className: tooltipStyles.className,\n style: {\n ...tooltipStyles.style,\n ...transitionStyles,\n ...mergeStyles,\n zIndex: zIndex as React.CSSProperties['zIndex'],\n top: tooltip.y ?? 0,\n left: tooltip.x ?? 0,\n },\n })}\n >\n {label}\n <FloatingArrow\n ref={arrowRef}\n arrowX={tooltip.arrowX}\n arrowY={tooltip.arrowY}\n visible={withArrow}\n position={tooltip.placement}\n arrowSize={arrowSize!}\n arrowOffset={arrowOffset!}\n arrowRadius={arrowRadius!}\n arrowPosition={arrowPosition!}\n {...getStyles('arrow')}\n />\n </Box>\n )}\n </Transition>\n </OptionalPortal>\n </>\n );\n }\n\n // fallback to children-based approach\n const childProps = child!.props as any;\n const targetRef = useMergedRef(tooltip.reference, getRefProp(child), ref);\n const transition = getTransitionProps(transitionProps, { duration: 100, transition: 'fade' });\n\n return (\n <>\n <OptionalPortal {...portalProps} withinPortal={withinPortal}>\n <Transition\n {...transition}\n keepMounted={keepMounted}\n mounted={!disabled && !!tooltip.opened}\n duration={tooltip.isGroupPhase ? 10 : transition.duration}\n >\n {(transitionStyles) => (\n <Box\n {...others}\n data-fixed={floatingStrategy === 'fixed' || undefined}\n variant={variant}\n mod={[{ multiline, interactive: interactiveMod }, mod]}\n {...tooltip.getFloatingProps({\n ref: tooltip.floating,\n className: getStyles('tooltip').className,\n style: {\n ...getStyles('tooltip').style,\n ...transitionStyles,\n ...mergeStyles,\n zIndex: zIndex as React.CSSProperties['zIndex'],\n top: tooltip.y ?? 0,\n left: tooltip.x ?? 0,\n },\n })}\n >\n {label}\n <FloatingArrow\n ref={arrowRef}\n arrowX={tooltip.arrowX}\n arrowY={tooltip.arrowY}\n visible={withArrow}\n position={tooltip.placement}\n arrowSize={arrowSize}\n arrowOffset={arrowOffset}\n arrowRadius={arrowRadius}\n arrowPosition={arrowPosition}\n {...getStyles('arrow')}\n />\n </Box>\n )}\n </Transition>\n </OptionalPortal>\n\n {cloneElement(\n child!,\n tooltip.getReferenceProps({\n onClick,\n onMouseEnter,\n onMouseLeave,\n onMouseMove: props.onMouseMove,\n onPointerDown: props.onPointerDown,\n onPointerEnter: props.onPointerEnter,\n ...childProps,\n className: cx(className, childProps.className),\n [refProp]: targetRef,\n })\n )}\n </>\n );\n});\n\nTooltip.classes = classes;\nTooltip.varsResolver = varsResolver;\nTooltip.displayName = '@mantine/core/Tooltip';\nTooltip.Floating = TooltipFloating;\nTooltip.Group = TooltipGroup;\n\nexport namespace Tooltip {\n export type Props = TooltipProps;\n export type Factory = TooltipFactory;\n export type CssVariables = TooltipCssVariables;\n export type StylesNames = TooltipStylesNames;\n\n export namespace Group {\n export type Props = TooltipGroupProps;\n export type ContextValue = TooltipGroupContextValue;\n }\n\n export namespace Floating {\n export type Props = TooltipFloatingProps;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0GA,MAAM,eAAe;CACnB,UAAU;CACV,SAAS;CACT,cAAc;CACd,WAAW;CACX,aAAa;CACb,aAAa;CACb,eAAe;CACf,QAAQ;CACR,iBAAiB;EAAE,UAAU;EAAK,YAAY;CAAO;CACrD,QAAQ;EAAE,OAAO;EAAM,OAAO;EAAO,OAAO;CAAM;CAClD,QAAQ,iBAAiB,SAAS;CAClC,aAAa;EAAE,MAAM;EAAM,OAAO;EAAM,QAAQ;CAAM;AACxD;AAEA,MAAM,eAAe,oBAClB,OAAO,EAAE,QAAQ,OAAO,SAAS,mBAAmB;CACnD,MAAM,SAAS,MAAM,qBAAqB;EACxC;EACA,OAAO,SAAS,MAAM;EACtB;EACA,SAAS,WAAW;CACtB,CAAC;CAED,OAAO,EACL,SAAS;EACP,oBAAoB,WAAW,KAAA,IAAY,KAAA,IAAY,UAAU,MAAM;EACvE,gBAAgB,QAAQ,OAAO,aAAa,KAAA;EAC5C,mBAAmB,QAAQ,OAAO,QAAQ,KAAA;CAC5C,EACF;AACF,CACF;AAEA,MAAa,UAAU,SAAyB,WAAW;CACzD,MAAM,QAAQ,SAAS,WAAW,cAAc,MAAM;CACtD,MAAM,EACJ,UACA,UACA,SACA,OACA,WACA,YACA,kBACA,QACA,eACA,cACA,QACA,OACA,YACA,QACA,UACA,OACA,WACA,WACA,WACA,aACA,aACA,eACA,QACA,iBACA,WACA,QACA,aACA,QACA,UACA,SACA,cACA,cACA,QACA,SACA,aACA,MACA,aACA,KACA,kBACA,aACA,cACA,YACA,QACA,KACA,GAAG,WACD;CAEJ,MAAM,EAAE,QAAQ,aAAa;CAC7B,MAAM,WAAW,OAAuB,IAAI;CAE5C,MAAM,UAAU,WAAW;EACzB,UAAU,oBAA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QAAQ,kBAAkB;EACxB;EACA;EACA;EACA,aAAa,MAAM;EACnB,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACtB,GAAG;EACH,WAAW,GAAG,WAAW,WAAW,SAAS;GAC5C,UAAU;CACb,CAAC,CACH,CACA,EAAA,CAAA;AAEN,CAAC;AAED,QAAQ,UAAUA;AAClB,QAAQ,eAAe;AACvB,QAAQ,cAAc;AACtB,QAAQ,WAAW;AACnB,QAAQ,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.module.mjs","names":[],"sources":["../../../src/components/Tooltip/Tooltip.module.css"],"sourcesContent":[".tooltip {\n --tooltip-radius: var(--mantine-radius-default);\n\n position: absolute;\n padding: calc(var(--mantine-spacing-xs) / 2) var(--mantine-spacing-xs);\n pointer-events: none;\n font-size: var(--mantine-font-size-sm);\n white-space: nowrap;\n border-radius: var(--tooltip-radius);\n\n @mixin where-light {\n background-color: var(--tooltip-bg, var(--mantine-color-gray-9));\n color: var(--tooltip-color, var(--mantine-color-white));\n }\n\n @mixin where-dark {\n background-color: var(--tooltip-bg, var(--mantine-color-gray-2));\n color: var(--tooltip-color, var(--mantine-color-black));\n }\n\n &:where([data-multiline]) {\n white-space: normal;\n }\n\n &:where([data-fixed]) {\n position: fixed;\n }\n}\n\n.arrow {\n background-color: inherit;\n border: 0;\n z-index: 1;\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"Tooltip.module.mjs","names":[],"sources":["../../../src/components/Tooltip/Tooltip.module.css"],"sourcesContent":[".tooltip {\n --tooltip-radius: var(--mantine-radius-default);\n\n position: absolute;\n padding: calc(var(--mantine-spacing-xs) / 2) var(--mantine-spacing-xs);\n pointer-events: none;\n font-size: var(--mantine-font-size-sm);\n white-space: nowrap;\n border-radius: var(--tooltip-radius);\n\n @mixin where-light {\n background-color: var(--tooltip-bg, var(--mantine-color-gray-9));\n color: var(--tooltip-color, var(--mantine-color-white));\n }\n\n @mixin where-dark {\n background-color: var(--tooltip-bg, var(--mantine-color-gray-2));\n color: var(--tooltip-color, var(--mantine-color-black));\n }\n\n &:where([data-multiline]) {\n white-space: normal;\n }\n\n &:where([data-fixed]) {\n position: fixed;\n }\n\n &:where([data-interactive]) {\n pointer-events: auto;\n }\n}\n\n.arrow {\n background-color: inherit;\n border: 0;\n z-index: 1;\n}\n"],"mappings":""}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { TooltipGroupContext } from "./TooltipGroup/TooltipGroup.mjs";
|
|
3
3
|
import { use, useCallback, useRef, useState } from "react";
|
|
4
4
|
import { useId as useId$1, useIsomorphicEffect } from "@mantine/hooks";
|
|
5
|
-
import { arrow, autoUpdate, flip, inline, offset, shift, useDelayGroup, useDismiss, useFloating, useFocus, useHover, useInteractions, useRole } from "@floating-ui/react";
|
|
5
|
+
import { arrow, autoUpdate, flip, inline, offset, safePolygon, shift, useDelayGroup, useDismiss, useFloating, useFocus, useHover, useInteractions, useRole } from "@floating-ui/react";
|
|
6
6
|
//#region packages/@mantine/core/src/components/Tooltip/use-tooltip.ts
|
|
7
7
|
function getDefaultMiddlewares(middlewares) {
|
|
8
8
|
if (middlewares === void 0) return {
|
|
@@ -55,7 +55,8 @@ function useTooltip(settings) {
|
|
|
55
55
|
open: settings.openDelay,
|
|
56
56
|
close: settings.closeDelay
|
|
57
57
|
},
|
|
58
|
-
mouseOnly: !settings.events?.touch
|
|
58
|
+
mouseOnly: !settings.events?.touch,
|
|
59
|
+
handleClose: settings.interactive ? safePolygon() : null
|
|
59
60
|
}),
|
|
60
61
|
useFocus(context, {
|
|
61
62
|
enabled: settings.events?.focus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tooltip.mjs","names":["useId"],"sources":["../../../src/components/Tooltip/use-tooltip.ts"],"sourcesContent":["import { use, useCallback, useRef, useState } from 'react';\nimport {\n arrow,\n autoUpdate,\n flip,\n inline,\n offset,\n shift,\n useDelayGroup,\n useDismiss,\n useFloating,\n useFocus,\n useHover,\n useInteractions,\n useRole,\n type Middleware,\n} from '@floating-ui/react';\nimport { useId, useIsomorphicEffect } from '@mantine/hooks';\nimport { FloatingAxesOffsets, FloatingPosition, FloatingStrategy } from '../../utils/Floating';\nimport { type TooltipMiddlewares } from './Tooltip.types';\nimport { TooltipGroupContext } from './TooltipGroup/TooltipGroup';\n\ninterface UseTooltip {\n position: FloatingPosition;\n closeDelay?: number;\n openDelay?: number;\n onPositionChange?: (position: FloatingPosition) => void;\n opened?: boolean;\n defaultOpened?: boolean;\n offset: number | FloatingAxesOffsets;\n arrowRef?: React.RefObject<HTMLDivElement | null>;\n arrowOffset?: number;\n events?: { hover: boolean; focus: boolean; touch: boolean };\n inline?: boolean;\n strategy?: FloatingStrategy;\n middlewares?: TooltipMiddlewares;\n}\n\nfunction getDefaultMiddlewares(middlewares: TooltipMiddlewares | undefined): TooltipMiddlewares {\n if (middlewares === undefined) {\n return { shift: true, flip: true };\n }\n\n const result = { ...middlewares };\n if (middlewares.shift === undefined) {\n result.shift = true;\n }\n\n if (middlewares.flip === undefined) {\n result.flip = true;\n }\n\n return result;\n}\n\nfunction getTooltipMiddlewares(settings: UseTooltip) {\n const middlewaresOptions = getDefaultMiddlewares(settings.middlewares);\n const middlewares: Middleware[] = [offset(settings.offset)];\n\n if (middlewaresOptions.shift) {\n middlewares.push(\n shift(\n typeof middlewaresOptions.shift === 'boolean'\n ? { padding: 8 }\n : { padding: 8, ...middlewaresOptions.shift }\n )\n );\n }\n\n if (middlewaresOptions.flip) {\n middlewares.push(\n typeof middlewaresOptions.flip === 'boolean' ? flip() : flip(middlewaresOptions.flip)\n );\n }\n\n middlewares.push(arrow({ element: settings.arrowRef!, padding: settings.arrowOffset }));\n\n if (middlewaresOptions.inline) {\n middlewares.push(\n typeof middlewaresOptions.inline === 'boolean' ? inline() : inline(middlewaresOptions.inline)\n );\n } else if (settings.inline) {\n middlewares.push(inline());\n }\n\n return middlewares;\n}\n\nexport function useTooltip(settings: UseTooltip) {\n const [uncontrolledOpened, setUncontrolledOpened] = useState(settings.defaultOpened);\n const controlled = typeof settings.opened === 'boolean';\n const opened = controlled ? settings.opened : uncontrolledOpened;\n const withinGroup = use(TooltipGroupContext).withinGroup;\n const uid = useId();\n\n const onChange = useCallback(\n (_opened: boolean) => {\n setUncontrolledOpened(_opened);\n\n if (_opened) {\n setCurrentId(uid);\n }\n },\n [uid]\n );\n\n const {\n x,\n y,\n context,\n refs,\n placement,\n middlewareData: { arrow: { x: arrowX, y: arrowY } = {} },\n } = useFloating({\n strategy: settings.strategy,\n placement: settings.position,\n open: opened,\n onOpenChange: onChange,\n middleware: getTooltipMiddlewares(settings),\n whileElementsMounted: autoUpdate,\n });\n\n const { delay: groupDelay, currentId, setCurrentId } = useDelayGroup(context, { id: uid });\n\n const { getReferenceProps, getFloatingProps } = useInteractions([\n useHover(context, {\n enabled: settings.events?.hover,\n delay: withinGroup ? groupDelay : { open: settings.openDelay, close: settings.closeDelay },\n mouseOnly: !settings.events?.touch,\n }),\n useFocus(context, { enabled: settings.events?.focus, visibleOnly: true }),\n useRole(context, { role: 'tooltip' }),\n // Cannot be used with controlled tooltip, page jumps\n useDismiss(context, { enabled: typeof settings.opened === 'undefined' }),\n ]);\n\n const previousPlacementRef = useRef(placement);\n useIsomorphicEffect(() => {\n if (previousPlacementRef.current !== placement) {\n previousPlacementRef.current = placement;\n settings.onPositionChange?.(placement);\n }\n }, [placement]);\n\n const isGroupPhase = opened && currentId && currentId !== uid;\n\n return {\n x,\n y,\n arrowX,\n arrowY,\n reference: refs.setReference,\n floating: refs.setFloating,\n getFloatingProps,\n getReferenceProps,\n isGroupPhase,\n opened,\n placement,\n };\n}\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"use-tooltip.mjs","names":["useId"],"sources":["../../../src/components/Tooltip/use-tooltip.ts"],"sourcesContent":["import { use, useCallback, useRef, useState } from 'react';\nimport {\n arrow,\n autoUpdate,\n flip,\n inline,\n offset,\n safePolygon,\n shift,\n useDelayGroup,\n useDismiss,\n useFloating,\n useFocus,\n useHover,\n useInteractions,\n useRole,\n type Middleware,\n} from '@floating-ui/react';\nimport { useId, useIsomorphicEffect } from '@mantine/hooks';\nimport { FloatingAxesOffsets, FloatingPosition, FloatingStrategy } from '../../utils/Floating';\nimport { type TooltipMiddlewares } from './Tooltip.types';\nimport { TooltipGroupContext } from './TooltipGroup/TooltipGroup';\n\ninterface UseTooltip {\n position: FloatingPosition;\n closeDelay?: number;\n openDelay?: number;\n onPositionChange?: (position: FloatingPosition) => void;\n opened?: boolean;\n defaultOpened?: boolean;\n offset: number | FloatingAxesOffsets;\n arrowRef?: React.RefObject<HTMLDivElement | null>;\n arrowOffset?: number;\n events?: { hover: boolean; focus: boolean; touch: boolean };\n interactive?: boolean;\n inline?: boolean;\n strategy?: FloatingStrategy;\n middlewares?: TooltipMiddlewares;\n}\n\nfunction getDefaultMiddlewares(middlewares: TooltipMiddlewares | undefined): TooltipMiddlewares {\n if (middlewares === undefined) {\n return { shift: true, flip: true };\n }\n\n const result = { ...middlewares };\n if (middlewares.shift === undefined) {\n result.shift = true;\n }\n\n if (middlewares.flip === undefined) {\n result.flip = true;\n }\n\n return result;\n}\n\nfunction getTooltipMiddlewares(settings: UseTooltip) {\n const middlewaresOptions = getDefaultMiddlewares(settings.middlewares);\n const middlewares: Middleware[] = [offset(settings.offset)];\n\n if (middlewaresOptions.shift) {\n middlewares.push(\n shift(\n typeof middlewaresOptions.shift === 'boolean'\n ? { padding: 8 }\n : { padding: 8, ...middlewaresOptions.shift }\n )\n );\n }\n\n if (middlewaresOptions.flip) {\n middlewares.push(\n typeof middlewaresOptions.flip === 'boolean' ? flip() : flip(middlewaresOptions.flip)\n );\n }\n\n middlewares.push(arrow({ element: settings.arrowRef!, padding: settings.arrowOffset }));\n\n if (middlewaresOptions.inline) {\n middlewares.push(\n typeof middlewaresOptions.inline === 'boolean' ? inline() : inline(middlewaresOptions.inline)\n );\n } else if (settings.inline) {\n middlewares.push(inline());\n }\n\n return middlewares;\n}\n\nexport function useTooltip(settings: UseTooltip) {\n const [uncontrolledOpened, setUncontrolledOpened] = useState(settings.defaultOpened);\n const controlled = typeof settings.opened === 'boolean';\n const opened = controlled ? settings.opened : uncontrolledOpened;\n const withinGroup = use(TooltipGroupContext).withinGroup;\n const uid = useId();\n\n const onChange = useCallback(\n (_opened: boolean) => {\n setUncontrolledOpened(_opened);\n\n if (_opened) {\n setCurrentId(uid);\n }\n },\n [uid]\n );\n\n const {\n x,\n y,\n context,\n refs,\n placement,\n middlewareData: { arrow: { x: arrowX, y: arrowY } = {} },\n } = useFloating({\n strategy: settings.strategy,\n placement: settings.position,\n open: opened,\n onOpenChange: onChange,\n middleware: getTooltipMiddlewares(settings),\n whileElementsMounted: autoUpdate,\n });\n\n const { delay: groupDelay, currentId, setCurrentId } = useDelayGroup(context, { id: uid });\n\n const { getReferenceProps, getFloatingProps } = useInteractions([\n useHover(context, {\n enabled: settings.events?.hover,\n delay: withinGroup ? groupDelay : { open: settings.openDelay, close: settings.closeDelay },\n mouseOnly: !settings.events?.touch,\n handleClose: settings.interactive ? safePolygon() : null,\n }),\n useFocus(context, { enabled: settings.events?.focus, visibleOnly: true }),\n useRole(context, { role: 'tooltip' }),\n // Cannot be used with controlled tooltip, page jumps\n useDismiss(context, { enabled: typeof settings.opened === 'undefined' }),\n ]);\n\n const previousPlacementRef = useRef(placement);\n useIsomorphicEffect(() => {\n if (previousPlacementRef.current !== placement) {\n previousPlacementRef.current = placement;\n settings.onPositionChange?.(placement);\n }\n }, [placement]);\n\n const isGroupPhase = opened && currentId && currentId !== uid;\n\n return {\n x,\n y,\n arrowX,\n arrowY,\n reference: refs.setReference,\n floating: refs.setFloating,\n getFloatingProps,\n getReferenceProps,\n isGroupPhase,\n opened,\n placement,\n };\n}\n"],"mappings":";;;;;;AAwCA,SAAS,sBAAsB,aAAiE;CAC9F,IAAI,gBAAgB,KAAA,GAClB,OAAO;EAAE,OAAO;EAAM,MAAM;CAAK;CAGnC,MA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N,cAAc;EACd,YAAY,sBAAsB,QAAQ;EAC1C,sBAAsB;CACxB,CAAC;CAED,MAAM,EAAE,OAAO,YAAY,WAAW,iBAAiB,cAAc,SAAS,EAAE,IAAI,IAAI,CAAC;CAEzF,MAAM,EAAE,mBAAmB,qBAAqB,gBAAgB;EAC9D,SAAS,SAAS;GAChB,SAAS,SAAS,QAAQ;GAC1B,OAAO,cAAc,aAAa;IAAE,MAAM,SAAS;IAAW,OAAO,SAAS;GAAW;GACzF,WAAW,CAAC,SAAS,QAAQ;GAC7B,aAAa,SAAS,cAAc,YAAY,IAAI;EACtD,CAAC;EACD,SAAS,SAAS;GAAE,SAAS,SAAS,QAAQ;GAAO,aAAa;EAAK,CAAC;EACxE,QAAQ,SAAS,EAAE,MAAM,UAAU,CAAC;EAEpC,WAAW,SAAS,EAAE,SAAS,OAAO,SAAS,WAAW,YAAY,CAAC;CACzE,CAAC;CAED,MAAM,uBAAuB,OAAO,SAAS;CAC7C,0BAA0B;EACxB,IAAI,qBAAqB,YAAY,WAAW;GAC9C,qBAAqB,UAAU;GAC/B,SAAS,mBAAmB,SAAS;EACvC;CACF,GAAG,CAAC,SAAS,CAAC;CAEd,MAAM,eAAe,UAAU,aAAa,cAAc;CAE1D,OAAO;EACL;EACA;EACA;EACA;EACA,WAAW,KAAK;EAChB,UAAU,KAAK;EACf;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SafePolygonOptions } from '@floating-ui/react';
|
|
1
2
|
import { BoxProps, ElementProps, Factory, MantineColor, StylesApiProps } from '../../core';
|
|
2
3
|
import { ComboboxLikeStylesNames } from '../Combobox';
|
|
3
4
|
import { __BaseInputProps, __InputStylesNames, ClearSectionMode, InputClearButtonProps, InputVariant } from '../Input';
|
|
@@ -19,6 +20,7 @@ export interface CascaderFormatValueInput {
|
|
|
19
20
|
options: CascaderOption[];
|
|
20
21
|
}
|
|
21
22
|
export type CascaderFormatValue = (input: CascaderFormatValueInput) => React.ReactNode;
|
|
23
|
+
export type CascaderSafeAreaPolygonOptions = Omit<SafePolygonOptions, 'blockPointerEvents'>;
|
|
22
24
|
export type CascaderStylesNames = __InputStylesNames | ComboboxLikeStylesNames | 'columnsList' | 'columnsOverflow' | 'column' | 'columnScroll' | 'columnOption' | 'columnOptionLabel' | 'columnOptionIcon' | 'columnOptionCheck' | 'columnEmpty' | 'flatOption';
|
|
23
25
|
export interface CascaderProps extends BoxProps, __BaseInputProps, StylesApiProps<CascaderFactory>, ElementProps<'input', 'size' | 'value' | 'defaultValue' | 'onChange'> {
|
|
24
26
|
/** Hierarchical options data */
|
|
@@ -43,6 +45,8 @@ export interface CascaderProps extends BoxProps, __BaseInputProps, StylesApiProp
|
|
|
43
45
|
withColumns?: boolean;
|
|
44
46
|
/** Determines how the next column is opened @default 'click' */
|
|
45
47
|
expandTrigger?: 'click' | 'hover';
|
|
48
|
+
/** Determines whether the next column stays open while the cursor moves toward it, applicable only when `expandTrigger="hover"`. Pass an object to configure safe polygon behavior. @default true */
|
|
49
|
+
safeAreaPolygon?: boolean | CascaderSafeAreaPolygonOptions;
|
|
46
50
|
/** If set, options can be searched by their flattened paths @default false */
|
|
47
51
|
searchable?: boolean;
|
|
48
52
|
/** Controlled search value */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GetStylesApi } from '../../core';
|
|
2
2
|
import { ScrollAreaProps } from '../ScrollArea';
|
|
3
|
-
import type { CascaderOption, CascaderStylesNames } from './Cascader';
|
|
3
|
+
import type { CascaderOption, CascaderSafeAreaPolygonOptions, CascaderStylesNames } from './Cascader';
|
|
4
4
|
type CascaderColumnsGetStyles = GetStylesApi<{
|
|
5
5
|
props: any;
|
|
6
6
|
stylesNames: CascaderStylesNames;
|
|
@@ -27,9 +27,10 @@ export interface CascaderColumnsProps {
|
|
|
27
27
|
onColumnsMouseLeave: (() => void) | undefined;
|
|
28
28
|
onPointerActivity: (() => void) | undefined;
|
|
29
29
|
listId: string | undefined;
|
|
30
|
+
safeAreaPolygon: boolean | CascaderSafeAreaPolygonOptions | undefined;
|
|
30
31
|
}
|
|
31
32
|
export declare function getCascaderOptionId(listId: string | undefined, level: number, value: string): string | undefined;
|
|
32
|
-
export declare function CascaderColumns({ data, activePath, value, keyboardNav, withCheckIcon, checkIconPosition, renderOption, columnWidth, maxDisplayedLevels, previousLevelsControlLabel, nextLevelsControlLabel, maxDropdownHeight, nothingFoundMessage, getStyles, unstyled, scrollAreaProps, onOptionClick, onOptionMouseEnter, onColumnsMouseLeave, onPointerActivity, listId, }: CascaderColumnsProps): import("react/jsx-runtime").JSX.Element;
|
|
33
|
+
export declare function CascaderColumns({ data, activePath, value, keyboardNav, withCheckIcon, checkIconPosition, renderOption, columnWidth, maxDisplayedLevels, previousLevelsControlLabel, nextLevelsControlLabel, maxDropdownHeight, nothingFoundMessage, getStyles, unstyled, scrollAreaProps, onOptionClick, onOptionMouseEnter, onColumnsMouseLeave, onPointerActivity, listId, safeAreaPolygon, }: CascaderColumnsProps): import("react/jsx-runtime").JSX.Element;
|
|
33
34
|
export declare namespace CascaderColumns {
|
|
34
35
|
var displayName: string;
|
|
35
36
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CascaderOption, CascaderSafeAreaPolygonOptions } from './Cascader';
|
|
2
|
+
export interface CascaderSafeAreaArmInput {
|
|
3
|
+
level: number;
|
|
4
|
+
reference: HTMLElement;
|
|
5
|
+
floating: HTMLElement;
|
|
6
|
+
clientX: number;
|
|
7
|
+
clientY: number;
|
|
8
|
+
}
|
|
9
|
+
export interface UseCascaderSafeAreaInput {
|
|
10
|
+
safeAreaPolygon: boolean | CascaderSafeAreaPolygonOptions | undefined;
|
|
11
|
+
onFlush: (level: number, option: CascaderOption) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function useCascaderSafeArea({ safeAreaPolygon, onFlush }: UseCascaderSafeAreaInput): {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
arm: ({ level, reference, floating, clientX, clientY }: CascaderSafeAreaArmInput) => void;
|
|
16
|
+
disarm: () => void;
|
|
17
|
+
isBlocked: (level: number) => boolean;
|
|
18
|
+
setPending: (level: number, option: CascaderOption) => void;
|
|
19
|
+
clearPending: (level: number, option: CascaderOption) => void;
|
|
20
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BoxProps, ElementProps, Factory, MantineRadius, StylesApiProps } from '../../../core';
|
|
2
2
|
export interface CheckboxCardContextValue {
|
|
3
3
|
checked: boolean;
|
|
4
|
+
indeterminate?: boolean;
|
|
4
5
|
}
|
|
5
6
|
export declare const CheckboxCardContext: import("react").Context<CheckboxCardContextValue | null>;
|
|
6
7
|
export type CheckboxCardStylesNames = 'card';
|
|
@@ -14,6 +15,8 @@ export interface CheckboxCardProps extends BoxProps, StylesApiProps<CheckboxCard
|
|
|
14
15
|
defaultChecked?: boolean;
|
|
15
16
|
/** Called when value changes */
|
|
16
17
|
onChange?: (checked: boolean) => void;
|
|
18
|
+
/** Indeterminate state of the checkbox. If set, `checked` prop is ignored and `aria-checked` is set to `mixed` */
|
|
19
|
+
indeterminate?: boolean;
|
|
17
20
|
/** Adds border to the root element */
|
|
18
21
|
withBorder?: boolean;
|
|
19
22
|
/** Key of `theme.radius` or any valid CSS value to set `border-radius`, numbers are converted to rem @default theme.defaultRadius */
|
|
@@ -23,11 +23,11 @@ export interface __ColorPickerProps {
|
|
|
23
23
|
swatchesPerRow?: number;
|
|
24
24
|
/** Component size @default 'md' */
|
|
25
25
|
size?: MantineSize | (string & {});
|
|
26
|
+
/** If set, the component takes 100% width of its container @default false */
|
|
27
|
+
fullWidth?: boolean;
|
|
26
28
|
}
|
|
27
29
|
export interface ColorPickerProps extends BoxProps, __ColorPickerProps, StylesApiProps<ColorPickerFactory>, ElementProps<'div', 'onChange' | 'value' | 'defaultValue'> {
|
|
28
30
|
__staticSelector?: string;
|
|
29
|
-
/** If set, the component takes 100% width of its container @default false */
|
|
30
|
-
fullWidth?: boolean;
|
|
31
31
|
/** If set, interactive elements (sliders thumbs and swatches) are focusable with keyboard @default true */
|
|
32
32
|
focusable?: boolean;
|
|
33
33
|
/** Saturation slider `aria-label` */
|
|
@@ -11,6 +11,8 @@ export interface PasswordInputProps extends BoxProps, Omit<__BaseInputProps, 'po
|
|
|
11
11
|
}>;
|
|
12
12
|
/** Props passed down to the visibility toggle button */
|
|
13
13
|
visibilityToggleButtonProps?: Record<string, any>;
|
|
14
|
+
/** If set, the visibility toggle button is focusable with keyboard @default `false` */
|
|
15
|
+
visibilityToggleFocusable?: boolean;
|
|
14
16
|
/** If set, the input value is visible */
|
|
15
17
|
visible?: boolean;
|
|
16
18
|
/** If set, the input value is visible by default */
|
|
@@ -35,6 +35,8 @@ export interface TooltipProps extends TooltipBaseProps {
|
|
|
35
35
|
focus: boolean;
|
|
36
36
|
touch: boolean;
|
|
37
37
|
};
|
|
38
|
+
/** If set, the tooltip stays open while the pointer moves from the target to the tooltip and remains over it. Required by [WCAG 1.4.13](https://www.w3.org/WAI/WCAG21/Understanding/content-on-hover-or-focus.html) if the tooltip contains interactive content. Note that an interactive tooltip intercepts pointer events of the content it overlaps @default false */
|
|
39
|
+
interactive?: boolean;
|
|
38
40
|
/** Must be set if the tooltip target is an inline element */
|
|
39
41
|
inline?: boolean;
|
|
40
42
|
/** If set, the tooltip is not unmounted from the DOM when hidden, `display: none` styles are applied instead */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantine/core",
|
|
3
|
-
"version": "9.5.1
|
|
3
|
+
"version": "9.5.1",
|
|
4
4
|
"description": "React components library focused on usability, accessibility and developer experience",
|
|
5
5
|
"homepage": "https://mantine.dev/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"directory": "packages/@mantine/core"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@mantine/hooks": "9.5.1
|
|
46
|
+
"@mantine/hooks": "9.5.1",
|
|
47
47
|
"react": "^19.2.0",
|
|
48
48
|
"react-dom": "^19.2.0"
|
|
49
49
|
},
|
package/styles/Tooltip.css
CHANGED
package/styles/Tooltip.layer.css
CHANGED
package/styles.css
CHANGED
package/styles.layer.css
CHANGED