UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 3.77 kB
{"version":3,"file":"Thumb.cjs","names":["useSliderContext","Box","Transition"],"sources":["../../../../src/components/Slider/Thumb/Thumb.tsx"],"sourcesContent":["import { useState } from 'react';\nimport { Box } from '../../../core';\nimport { Transition, TransitionOverride } from '../../Transition';\nimport { useSliderContext } from '../Slider.context';\n\nexport interface ThumbProps extends Omit<React.ComponentProps<'div'>, 'value'> {\n max: number;\n min: number;\n value: number;\n position: number;\n dragging: boolean;\n label: React.ReactNode;\n onKeyDownCapture?: (event: React.KeyboardEvent<HTMLDivElement>) => void;\n onMouseDown?: (event: any) => void;\n labelTransitionProps: TransitionOverride | undefined;\n labelAlwaysOn: boolean | undefined;\n thumbLabel: string | undefined;\n showLabelOnHover: boolean | undefined;\n isHovered?: boolean;\n children?: React.ReactNode;\n disabled: boolean | undefined;\n orientation?: 'horizontal' | 'vertical';\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport function Thumb({\n max,\n min,\n value,\n position,\n label,\n dragging,\n onMouseDown,\n onKeyDownCapture,\n labelTransitionProps,\n labelAlwaysOn,\n thumbLabel,\n onFocus,\n onBlur,\n showLabelOnHover,\n isHovered,\n children = null,\n disabled,\n orientation = 'horizontal',\n ref,\n}: ThumbProps) {\n const { getStyles } = useSliderContext();\n\n const [focused, setFocused] = useState(false);\n\n const isVisible = labelAlwaysOn || dragging || focused || (showLabelOnHover && isHovered);\n\n return (\n <Box<'div'>\n tabIndex={disabled ? -1 : 0}\n role=\"slider\"\n aria-label={thumbLabel}\n aria-valuemax={max}\n aria-valuemin={min}\n aria-valuenow={value}\n aria-disabled={disabled}\n aria-orientation={orientation}\n ref={ref}\n __vars={{ '--slider-thumb-offset': `${position}%` }}\n {...getStyles('thumb', { focusable: true })}\n mod={{ dragging, disabled }}\n onFocus={(event) => {\n setFocused(true);\n typeof onFocus === 'function' && onFocus(event);\n }}\n onBlur={(event) => {\n setFocused(false);\n typeof onBlur === 'function' && onBlur(event);\n }}\n onTouchStart={onMouseDown}\n onMouseDown={onMouseDown}\n onKeyDownCapture={onKeyDownCapture}\n onClick={(event) => event.stopPropagation()}\n >\n {children}\n <Transition\n mounted={label != null && !!isVisible}\n transition=\"fade\"\n duration={0}\n {...labelTransitionProps}\n >\n {(transitionStyles) => (\n <div {...getStyles('label', { style: transitionStyles })}>{label}</div>\n )}\n </Transition>\n </Box>\n );\n}\n\nThumb.displayName = '@mantine/core/SliderThumb';\n"],"mappings":";;;;;;;;AA0BA,SAAgB,MAAM,EACpB,KACA,KACA,OACA,UACA,OACA,UACA,aACA,kBACA,sBACA,eACA,YACA,SACA,QACA,kBACA,WACA,WAAW,MACX,UACA,cAAc,cACd,OACa;CACb,MAAM,EAAE,cAAcA,uBAAAA,kBAAkB;CAExC,MAAM,CAAC,SAAS,eAAA,GAAA,MAAA,UAAuB,MAAM;CAE7C,MAAM,YAAY,iBAAiB,YAAY,WAAY,oBAAoB;AAE/E,QACE,iBAAA,GAAA,kBAAA,MAACC,YAAAA,KAAD;EACE,UAAU,WAAW,KAAK;EAC1B,MAAK;EACL,cAAY;EACZ,iBAAe;EACf,iBAAe;EACf,iBAAe;EACf,iBAAe;EACf,oBAAkB;EACb;EACL,QAAQ,EAAE,yBAAyB,GAAG,SAAS,IAAI;EACnD,GAAI,UAAU,SAAS,EAAE,WAAW,MAAM,CAAC;EAC3C,KAAK;GAAE;GAAU;GAAU;EAC3B,UAAU,UAAU;AAClB,cAAW,KAAK;AAChB,UAAO,YAAY,cAAc,QAAQ,MAAM;;EAEjD,SAAS,UAAU;AACjB,cAAW,MAAM;AACjB,UAAO,WAAW,cAAc,OAAO,MAAM;;EAE/C,cAAc;EACD;EACK;EAClB,UAAU,UAAU,MAAM,iBAAiB;YAxB7C,CA0BG,UACD,iBAAA,GAAA,kBAAA,KAACC,mBAAAA,YAAD;GACE,SAAS,SAAS,QAAQ,CAAC,CAAC;GAC5B,YAAW;GACX,UAAU;GACV,GAAI;cAEF,qBACA,iBAAA,GAAA,kBAAA,KAAC,OAAD;IAAK,GAAI,UAAU,SAAS,EAAE,OAAO,kBAAkB,CAAC;cAAG;IAAY,CAAA;GAE9D,CAAA,CACT;;;AAIV,MAAM,cAAc"}