UNPKG

@yamada-ui/react

Version:

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

1 lines 5.41 kB
{"version":3,"file":"alpha-slider.cjs","names":["createSlotComponent","alphaSliderStyle","useValue","checkersProps"],"sources":["../../../../src/components/alpha-slider/alpha-slider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { WithoutThemeProps } from \"../../core\"\nimport type { AlphaSliderStyle } from \"./alpha-slider.style\"\nimport { useMemo } from \"react\"\nimport { createSlotComponent } from \"../../core\"\nimport { useValue } from \"../../hooks/use-value\"\nimport { alphaToHex, convertColor } from \"../../utils\"\nimport { checkersProps } from \"../color-swatch\"\nimport { HueSlider } from \"../hue-slider\"\nimport { alphaSliderStyle } from \"./alpha-slider.style\"\n\ninterface ComponentContext\n extends Pick<\n Required<AlphaSliderRootProps>,\n \"color\" | \"max\" | \"min\" | \"orientation\"\n > {}\n\nexport const getAriaValueText = (alpha: number) => `${alpha * 100}%`\n\nexport interface AlphaSliderRootProps\n extends WithoutThemeProps<\n Omit<\n HueSlider.RootProps,\n \"color\" | \"max\" | \"step\" | \"thumbProps\" | \"trackProps\"\n >,\n AlphaSliderStyle\n > {\n /**\n * The color used for the slider.\n */\n color: string\n /**\n * The maximum allowed value of the slider. Cannot be less than min.\n *\n * @default 1\n */\n max?: number\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 0.01\n */\n step?: number\n /**\n * Props for the overlay element.\n */\n overlayProps?: AlphaSliderOverlayProps\n /**\n * Props for the thumb element.\n */\n thumbProps?: AlphaSliderThumbProps\n /**\n * Props for the track element.\n */\n trackProps?: AlphaSliderTrackProps\n}\n\nconst {\n ComponentContext,\n PropsContext: AlphaSliderPropsContext,\n useComponentContext,\n usePropsContext: useAlphaSliderPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<\n AlphaSliderRootProps,\n AlphaSliderStyle,\n ComponentContext\n>(\"alpha-slider\", alphaSliderStyle)\n\nexport { AlphaSliderPropsContext, useAlphaSliderPropsContext }\n\n/**\n * `AlphaSlider` is a component used to allow the user to select color transparency.\n *\n * @see https://yamada-ui.com/docs/components/alpha-slider\n */\nexport const AlphaSliderRoot = withProvider<\"input\", AlphaSliderRootProps>(\n ({\n children,\n color,\n max = 1,\n min = 0,\n orientation: orientationProp = \"horizontal\",\n overlayProps,\n thumbProps,\n trackProps,\n ...rest\n }) => {\n const orientation = useValue(orientationProp)\n const computedChildren = useMemo(() => {\n if (children) return children\n\n return (\n <AlphaSliderTrack {...trackProps}>\n <AlphaSliderThumb {...thumbProps} />\n\n <AlphaSliderOverlay {...overlayProps} />\n </AlphaSliderTrack>\n )\n }, [children, overlayProps, thumbProps, trackProps])\n const context = useMemo(\n () => ({ color, max, min, orientation }),\n [color, min, max, orientation],\n )\n\n return (\n <ComponentContext value={context}>\n <HueSlider.Root max={max} min={min} orientation={orientation} {...rest}>\n {computedChildren}\n </HueSlider.Root>\n </ComponentContext>\n )\n },\n \"root\",\n)({ getAriaValueText, step: 0.01 })\n\nexport interface AlphaSliderOverlayProps extends HueSlider.OverlayProps {}\n\nexport const AlphaSliderOverlay = withContext<\"div\", AlphaSliderOverlayProps>(\n HueSlider.Overlay,\n \"overlay\",\n)(undefined, ({ layers, ...rest }) => {\n const { color, max, min, orientation } = useComponentContext()\n\n layers ??= [\n checkersProps,\n {\n bgGradient: `linear(${[\n orientation === \"horizontal\" ? \"to-r\" : \"to-t\",\n convertColor(color)(\"hex\") + alphaToHex(min),\n convertColor(color)(\"hex\") + alphaToHex(max),\n ].join(\", \")})`,\n boxShadow: \"inner\",\n },\n ]\n\n return { layers, ...rest }\n})\n\nexport interface AlphaSliderTrackProps extends HueSlider.TrackProps {}\n\nexport const AlphaSliderTrack = withContext<\"div\", AlphaSliderTrackProps>(\n HueSlider.Track,\n \"track\",\n)()\n\nexport interface AlphaSliderThumbProps extends HueSlider.ThumbProps {}\n\nexport const AlphaSliderThumb = withContext<\"div\", AlphaSliderThumbProps>(\n HueSlider.Thumb,\n \"thumb\",\n)()\n"],"mappings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