@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 2.15 kB
Source Map (JSON)
{"version":3,"file":"ScrollAreaCorner.cjs","names":["useScrollAreaContext"],"sources":["../../../../src/components/ScrollArea/ScrollAreaCorner/ScrollAreaCorner.tsx"],"sourcesContent":["import { useState } from 'react';\nimport { useScrollAreaContext } from '../ScrollArea.context';\nimport { useResizeObserver } from '../use-resize-observer';\n\ninterface ScrollAreaCornerProps extends React.ComponentProps<'div'> {}\n\nexport function Corner(props: ScrollAreaCornerProps) {\n const { style, ...others } = props;\n const ctx = useScrollAreaContext();\n const [width, setWidth] = useState(0);\n const [height, setHeight] = useState(0);\n const hasSize = Boolean(width && height);\n\n useResizeObserver(ctx.scrollbarX, () => {\n const h = ctx.scrollbarX?.offsetHeight || 0;\n ctx.onCornerHeightChange(h);\n setHeight(h);\n });\n\n useResizeObserver(ctx.scrollbarY, () => {\n const w = ctx.scrollbarY?.offsetWidth || 0;\n ctx.onCornerWidthChange(w);\n setWidth(w);\n });\n\n return hasSize ? <div {...others} style={{ ...style, width, height }} /> : null;\n}\n\nexport function ScrollAreaCorner(props: ScrollAreaCornerProps) {\n const ctx = useScrollAreaContext();\n const hasBothScrollbarsVisible = Boolean(ctx.scrollbarX && ctx.scrollbarY);\n const hasCorner = ctx.type !== 'scroll' && hasBothScrollbarsVisible;\n return hasCorner ? <Corner {...props} /> : null;\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,OAAO,OAA8B;CACnD,MAAM,EAAE,OAAO,GAAG,WAAW;CAC7B,MAAM,MAAMA,2BAAAA,qBAAqB;CACjC,MAAM,CAAC,OAAO,aAAA,GAAA,MAAA,UAAqB,CAAC;CACpC,MAAM,CAAC,QAAQ,cAAA,GAAA,MAAA,UAAsB,CAAC;CACtC,MAAM,UAAU,QAAQ,SAAS,MAAM;CAEvC,4BAAA,kBAAkB,IAAI,kBAAkB;EACtC,MAAM,IAAI,IAAI,YAAY,gBAAgB;EAC1C,IAAI,qBAAqB,CAAC;EAC1B,UAAU,CAAC;CACb,CAAC;CAED,4BAAA,kBAAkB,IAAI,kBAAkB;EACtC,MAAM,IAAI,IAAI,YAAY,eAAe;EACzC,IAAI,oBAAoB,CAAC;EACzB,SAAS,CAAC;CACZ,CAAC;CAED,OAAO,UAAU,iBAAA,GAAA,kBAAA,KAAC,OAAD;EAAK,GAAI;EAAQ,OAAO;GAAE,GAAG;GAAO;GAAO;EAAO;CAAI,CAAA,IAAI;AAC7E;AAEA,SAAgB,iBAAiB,OAA8B;CAC7D,MAAM,MAAMA,2BAAAA,qBAAqB;CACjC,MAAM,2BAA2B,QAAQ,IAAI,cAAc,IAAI,UAAU;CAEzE,OADkB,IAAI,SAAS,YAAY,2BACxB,iBAAA,GAAA,kBAAA,KAAC,QAAD,EAAQ,GAAI,MAAQ,CAAA,IAAI;AAC7C"}