@bitrise/bitkit-v2 0.3.355 → 0.3.356
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.
|
@@ -26,24 +26,43 @@ var useIsContentOverflowing = (collapsedHeight) => {
|
|
|
26
26
|
const resizeObserver = new ResizeObserver(checkOverflow);
|
|
27
27
|
resizeObserver.observe(contentEl);
|
|
28
28
|
return () => resizeObserver.disconnect();
|
|
29
|
-
}, [collapsedHeight]);
|
|
29
|
+
}, [collapsedHeight, isOverflowing]);
|
|
30
30
|
return {
|
|
31
31
|
contentRef,
|
|
32
32
|
isOverflowing
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
var BitkitCollapsible = forwardRef((props, ref) => {
|
|
36
|
-
const { children, closedLabel = "Show less", collapsedHeight = "48px", defaultOpen, label, labelProps, onOpenChange, open, openLabel = "Show more", ...rest } = props;
|
|
36
|
+
const { children, closedLabel = "Show less", collapsedHeight = "48px", collapsedWidth, defaultOpen, disabled, hideMode, ids, label, labelProps, lazyMount, onExitComplete, onOpenChange, open, openLabel = "Show more", unmountOnExit, ...rest } = props;
|
|
37
37
|
const styles = useSlotRecipe({ key: "collapsible" })();
|
|
38
38
|
const { contentRef, isOverflowing } = useIsContentOverflowing(collapsedHeight);
|
|
39
39
|
const handleOpenChange = onOpenChange ? (details) => onOpenChange(details.open) : void 0;
|
|
40
|
+
if (!isOverflowing) return /* @__PURE__ */ jsxs(Box, {
|
|
41
|
+
ref,
|
|
42
|
+
css: styles.root,
|
|
43
|
+
...rest,
|
|
44
|
+
children: [label && /* @__PURE__ */ jsx(BitkitLabel, {
|
|
45
|
+
...labelProps,
|
|
46
|
+
children: label
|
|
47
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
48
|
+
ref: contentRef,
|
|
49
|
+
children
|
|
50
|
+
})]
|
|
51
|
+
});
|
|
40
52
|
return /* @__PURE__ */ jsxs(Collapsible.Root, {
|
|
41
53
|
ref,
|
|
42
54
|
collapsedHeight,
|
|
55
|
+
collapsedWidth,
|
|
43
56
|
css: styles.root,
|
|
44
57
|
defaultOpen,
|
|
58
|
+
disabled,
|
|
59
|
+
hideMode,
|
|
60
|
+
ids,
|
|
61
|
+
lazyMount,
|
|
62
|
+
onExitComplete,
|
|
45
63
|
onOpenChange: handleOpenChange,
|
|
46
64
|
open,
|
|
65
|
+
unmountOnExit,
|
|
47
66
|
...rest,
|
|
48
67
|
children: [
|
|
49
68
|
label && /* @__PURE__ */ jsx(BitkitLabel, {
|
|
@@ -57,7 +76,7 @@ var BitkitCollapsible = forwardRef((props, ref) => {
|
|
|
57
76
|
children
|
|
58
77
|
})
|
|
59
78
|
}),
|
|
60
|
-
|
|
79
|
+
/* @__PURE__ */ jsx(Collapsible.Trigger, {
|
|
61
80
|
css: styles.trigger,
|
|
62
81
|
children: /* @__PURE__ */ jsx(Collapsible.Context, { children: (api) => /* @__PURE__ */ jsxs(Fragment$1, { children: [api.open ? closedLabel : openLabel, api.open ? /* @__PURE__ */ jsx(IconChevronUp, { size: "16" }) : /* @__PURE__ */ jsx(IconChevronDown, { size: "16" })] }) })
|
|
63
82
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitkitCollapsible.js","names":[],"sources":["../../../lib/components/BitkitCollapsible/BitkitCollapsible.tsx"],"sourcesContent":["import { Box } from '@chakra-ui/react/box';\nimport { Collapsible, type CollapsibleRootProps } from '@chakra-ui/react/collapsible';\nimport { useSafeLayoutEffect } from '@chakra-ui/react/hooks';\nimport { useSlotRecipe } from '@chakra-ui/react/styled-system';\nimport { forwardRef, type ReactNode, useRef, useState } from 'react';\n\n// TODO: Investigate using AssetSelectChevron instead of IconChevronDown/IconChevronUp\nimport { IconChevronDown, IconChevronUp } from '../../icons';\nimport BitkitLabel, { type BitkitLabelProps } from '../BitkitLabel/BitkitLabel';\n\ntype UncontrolledProps = {\n defaultOpen?: boolean;\n open?: never;\n onOpenChange?: never;\n};\n\ntype ControlledProps = {\n defaultOpen?: never;\n onOpenChange: (open: boolean) => void;\n open: boolean;\n};\n\nexport type BitkitCollapsibleProps = Omit<\n CollapsibleRootProps,\n 'collapsedHeight' | 'defaultOpen' | 'onOpenChange' | 'open'\n> & {\n children: ReactNode;\n closedLabel?: string;\n collapsedHeight?: string;\n label?: string;\n labelProps?: Omit<BitkitLabelProps, 'children'>;\n openLabel?: string;\n} & (UncontrolledProps | ControlledProps);\n\n// contentRef sits on an unclamped wrapper *inside* Collapsible.Content, not on Content itself: when\n// closed, Content's own box is pinned to collapsedHeight (max-height + overflow), so a ResizeObserver\n// on Content can't see content that grows without changing Content's own (clamped) box - e.g. an image\n// or async child rendering more after mount. scrollHeight still reports the wrapper's true height\n// either way, clamped or not, so the read doesn't change - only where we watch for changes does.\n// collapsedHeight
|
|
1
|
+
{"version":3,"file":"BitkitCollapsible.js","names":[],"sources":["../../../lib/components/BitkitCollapsible/BitkitCollapsible.tsx"],"sourcesContent":["import { Box } from '@chakra-ui/react/box';\nimport { Collapsible, type CollapsibleRootProps } from '@chakra-ui/react/collapsible';\nimport { useSafeLayoutEffect } from '@chakra-ui/react/hooks';\nimport { useSlotRecipe } from '@chakra-ui/react/styled-system';\nimport { forwardRef, type ReactNode, useRef, useState } from 'react';\n\n// TODO: Investigate using AssetSelectChevron instead of IconChevronDown/IconChevronUp\nimport { IconChevronDown, IconChevronUp } from '../../icons';\nimport BitkitLabel, { type BitkitLabelProps } from '../BitkitLabel/BitkitLabel';\n\ntype UncontrolledProps = {\n defaultOpen?: boolean;\n open?: never;\n onOpenChange?: never;\n};\n\ntype ControlledProps = {\n defaultOpen?: never;\n onOpenChange: (open: boolean) => void;\n open: boolean;\n};\n\nexport type BitkitCollapsibleProps = Omit<\n CollapsibleRootProps,\n 'collapsedHeight' | 'defaultOpen' | 'onOpenChange' | 'open'\n> & {\n children: ReactNode;\n closedLabel?: string;\n collapsedHeight?: string;\n label?: string;\n labelProps?: Omit<BitkitLabelProps, 'children'>;\n openLabel?: string;\n} & (UncontrolledProps | ControlledProps);\n\n// contentRef sits on an unclamped wrapper *inside* Collapsible.Content, not on Content itself: when\n// closed, Content's own box is pinned to collapsedHeight (max-height + overflow), so a ResizeObserver\n// on Content can't see content that grows without changing Content's own (clamped) box - e.g. an image\n// or async child rendering more after mount. scrollHeight still reports the wrapper's true height\n// either way, clamped or not, so the read doesn't change - only where we watch for changes does.\n// isOverflowing and collapsedHeight are the effect's only dependencies. isOverflowing: BitkitCollapsible\n// renders a different tree depending on it (see below), moving contentRef to a different DOM node each\n// time it flips, so the effect must re-attach then. children is deliberately not a dependency: the\n// wrapper being unclamped means the observer already sees every content-driven size change on its own.\nconst useIsContentOverflowing = (collapsedHeight: string) => {\n const contentRef = useRef<HTMLDivElement>(null);\n const [isOverflowing, setIsOverflowing] = useState(true);\n\n useSafeLayoutEffect(() => {\n const contentEl = contentRef.current;\n const measureScope = contentEl?.parentElement;\n if (!contentEl || !measureScope) {\n return undefined;\n }\n\n // Appended as a sibling of contentEl (not document.body) so it inherits the same font-size and\n // CSS custom properties contentEl actually sees, resolving em/var(...) heights correctly - not\n // just px/rem, which don't depend on where in the tree they're resolved.\n const probe = document.createElement('div');\n probe.style.cssText = `position: absolute; visibility: hidden; pointer-events: none; height: ${collapsedHeight};`;\n measureScope.appendChild(probe);\n const collapsedHeightPx = probe.getBoundingClientRect().height;\n measureScope.removeChild(probe);\n\n const checkOverflow = () => setIsOverflowing(contentEl.scrollHeight > collapsedHeightPx);\n checkOverflow();\n\n if (typeof ResizeObserver === 'undefined') {\n return undefined;\n }\n\n const resizeObserver = new ResizeObserver(checkOverflow);\n resizeObserver.observe(contentEl);\n return () => resizeObserver.disconnect();\n }, [collapsedHeight, isOverflowing]);\n\n return { contentRef, isOverflowing };\n};\n\nconst BitkitCollapsible = forwardRef<HTMLDivElement, BitkitCollapsibleProps>((props, ref) => {\n const {\n children,\n closedLabel = 'Show less',\n collapsedHeight = '48px',\n collapsedWidth,\n defaultOpen,\n disabled,\n hideMode,\n ids,\n label,\n labelProps,\n lazyMount,\n onExitComplete,\n onOpenChange,\n open,\n openLabel = 'Show more',\n unmountOnExit,\n ...rest\n } = props;\n\n const recipe = useSlotRecipe({ key: 'collapsible' });\n const styles = recipe();\n\n const { contentRef, isOverflowing } = useIsContentOverflowing(collapsedHeight);\n\n const handleOpenChange = onOpenChange ? (details: { open: boolean }) => onOpenChange(details.open) : undefined;\n\n // zag's closed-state styling (min/max-height clamp, the fade-out pseudo-element) is driven purely by\n // Collapsible.Root defaulting to \"closed\" - it doesn't know or care whether collapsedHeight would\n // ever actually clip anything. Passing collapsedHeight and hiding only the trigger still leaves\n // content that fits pinned to that height and faded, so when it doesn't overflow we skip\n // Collapsible.Root/Content entirely and render plain markup instead of fighting the closed-state\n // styling with overrides. Only styles.root applies here - it carries the inherited color/textStyle,\n // which is all a non-collapsing block needs; styles.content's overflow/position/fade rules are\n // collapse-only and would clip content (a focus ring, an absolutely-positioned child) that isn't\n // meant to be clipped. contentRef sits directly under styles.root rather than under a styles.content\n // box, so measureScope (its parent) is styles.root in this branch and styles.content in the\n // overflowing one below - both carry the same inherited font-size, since textStyle now lives on\n // root and cascades down, so collapsedHeight's em/var(...) units resolve the same way in either\n // branch. disabled/ids/collapsedWidth/onExitComplete/lazyMount/unmountOnExit/hideMode\n // are zag/Ark machine props with no meaning on plain markup, so they're destructured out above and\n // only forwarded to Collapsible.Root below - otherwise they'd reach the DOM as unknown attributes.\n //\n // isOverflowing starts true, so every mount (even of content that turns out to fit) renders through\n // this Collapsible.Root tree first and flips to the plain tree below once measured - a real\n // remount of children, since the two trees don't share a component type at that position. Same\n // going the other way on a runtime resize. Accepted tradeoff: measuring requires a real layout\n // pass, and we don't have the content's size before that first render.\n if (!isOverflowing) {\n return (\n <Box ref={ref} css={styles.root} {...rest}>\n {label && <BitkitLabel {...labelProps}>{label}</BitkitLabel>}\n <Box ref={contentRef}>{children}</Box>\n </Box>\n );\n }\n\n return (\n <Collapsible.Root\n ref={ref}\n collapsedHeight={collapsedHeight}\n collapsedWidth={collapsedWidth}\n css={styles.root}\n defaultOpen={defaultOpen}\n disabled={disabled}\n hideMode={hideMode}\n ids={ids}\n lazyMount={lazyMount}\n onExitComplete={onExitComplete}\n onOpenChange={handleOpenChange}\n open={open}\n unmountOnExit={unmountOnExit}\n {...rest}\n >\n {label && <BitkitLabel {...labelProps}>{label}</BitkitLabel>}\n <Collapsible.Content css={styles.content}>\n <Box ref={contentRef}>{children}</Box>\n </Collapsible.Content>\n <Collapsible.Trigger css={styles.trigger}>\n <Collapsible.Context>\n {(api) => (\n <>\n {api.open ? closedLabel : openLabel}\n {api.open ? <IconChevronUp size=\"16\" /> : <IconChevronDown size=\"16\" />}\n </>\n )}\n </Collapsible.Context>\n </Collapsible.Trigger>\n </Collapsible.Root>\n );\n});\n\nBitkitCollapsible.displayName = 'BitkitCollapsible';\n\nexport default BitkitCollapsible;\n"],"mappings":";;;;;;;;;;AA2CA,IAAM,2BAA2B,oBAA4B;CAC3D,MAAM,aAAa,OAAuB,IAAI;CAC9C,MAAM,CAAC,eAAe,oBAAoB,SAAS,IAAI;CAEvD,0BAA0B;EACxB,MAAM,YAAY,WAAW;EAC7B,MAAM,eAAe,WAAW;EAChC,IAAI,CAAC,aAAa,CAAC,cACjB;EAMF,MAAM,QAAQ,SAAS,cAAc,KAAK;EAC1C,MAAM,MAAM,UAAU,yEAAyE,gBAAgB;EAC/G,aAAa,YAAY,KAAK;EAC9B,MAAM,oBAAoB,MAAM,sBAAsB,CAAC,CAAC;EACxD,aAAa,YAAY,KAAK;EAE9B,MAAM,sBAAsB,iBAAiB,UAAU,eAAe,iBAAiB;EACvF,cAAc;EAEd,IAAI,OAAO,mBAAmB,aAC5B;EAGF,MAAM,iBAAiB,IAAI,eAAe,aAAa;EACvD,eAAe,QAAQ,SAAS;EAChC,aAAa,eAAe,WAAW;CACzC,GAAG,CAAC,iBAAiB,aAAa,CAAC;CAEnC,OAAO;EAAE;EAAY;CAAc;AACrC;AAEA,IAAM,oBAA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e({
|
|
|
6
6
|
slots: [...collapsibleAnatomy.keys()],
|
|
7
7
|
base: {
|
|
8
8
|
root: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
width: "100%",
|
|
10
|
+
color: "text/body",
|
|
11
|
+
textStyle: "body/lg/regular"
|
|
12
12
|
},
|
|
13
13
|
content: {
|
|
14
14
|
overflow: "hidden",
|
|
15
|
-
color: "text/body",
|
|
16
|
-
textStyle: "body/lg/regular",
|
|
17
15
|
position: "relative",
|
|
18
16
|
_open: {
|
|
19
17
|
animationName: "expand-height",
|
|
@@ -35,7 +33,7 @@ var collapsibleSlotRecipe = defineSlotRecipe({
|
|
|
35
33
|
}
|
|
36
34
|
},
|
|
37
35
|
trigger: {
|
|
38
|
-
display: "
|
|
36
|
+
display: "flex",
|
|
39
37
|
alignItems: "center",
|
|
40
38
|
color: "text/link",
|
|
41
39
|
cursor: "pointer",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collapsible.recipe.js","names":[],"sources":["../../../lib/theme/slot-recipes/Collapsible.recipe.ts"],"sourcesContent":["import { collapsibleAnatomy } from '@chakra-ui/react/anatomy';\nimport { defineSlotRecipe } from '@chakra-ui/react/styled-system';\n\nconst collapsibleSlotRecipe = defineSlotRecipe({\n className: 'collapsible',\n slots: [...collapsibleAnatomy.keys()],\n base: {\n root: {\n
|
|
1
|
+
{"version":3,"file":"Collapsible.recipe.js","names":[],"sources":["../../../lib/theme/slot-recipes/Collapsible.recipe.ts"],"sourcesContent":["import { collapsibleAnatomy } from '@chakra-ui/react/anatomy';\nimport { defineSlotRecipe } from '@chakra-ui/react/styled-system';\n\nconst collapsibleSlotRecipe = defineSlotRecipe({\n className: 'collapsible',\n slots: [...collapsibleAnatomy.keys()],\n base: {\n root: {\n width: '100%',\n color: 'text/body',\n textStyle: 'body/lg/regular',\n },\n content: {\n overflow: 'hidden',\n position: 'relative',\n _open: {\n animationName: 'expand-height',\n animationDuration: 'moderate',\n },\n _closed: {\n animationName: 'collapse-height',\n animationDuration: 'moderate',\n _after: {\n content: '\"\"',\n position: 'absolute',\n insetInlineStart: 0,\n insetInlineEnd: 0,\n bottom: 0,\n height: '32',\n background: 'linear-gradient(to top, {colors.neutral.100}, transparent)',\n pointerEvents: 'none',\n },\n },\n },\n trigger: {\n display: 'flex',\n alignItems: 'center',\n color: 'text/link',\n cursor: 'pointer',\n gap: '4',\n textStyle: 'body/md/regular',\n paddingBlockStart: '8',\n width: 'fit-content',\n _hover: {\n color: 'text/link-hover',\n _active: {\n color: 'text/primary',\n },\n },\n _active: {\n color: 'text/primary',\n },\n },\n indicator: {},\n },\n});\n\nexport default collapsibleSlotRecipe;\n"],"mappings":";;;AAGA,IAAM,wBAAwB,iBAAiB;CAC7C,WAAW;CACX,OAAO,CAAC,GAAG,mBAAmB,KAAK,CAAC;CACpC,MAAM;EACJ,MAAM;GACJ,OAAO;GACP,OAAO;GACP,WAAW;EACb;EACA,SAAS;GACP,UAAU;GACV,UAAU;GACV,OAAO;IACL,eAAe;IACf,mBAAmB;GACrB;GACA,SAAS;IACP,eAAe;IACf,mBAAmB;IACnB,QAAQ;KACN,SAAS;KACT,UAAU;KACV,kBAAkB;KAClB,gBAAgB;KAChB,QAAQ;KACR,QAAQ;KACR,YAAY;KACZ,eAAe;IACjB;GACF;EACF;EACA,SAAS;GACP,SAAS;GACT,YAAY;GACZ,OAAO;GACP,QAAQ;GACR,KAAK;GACL,WAAW;GACX,mBAAmB;GACnB,OAAO;GACP,QAAQ;IACN,OAAO;IACP,SAAS,EACP,OAAO,eACT;GACF;GACA,SAAS,EACP,OAAO,eACT;EACF;EACA,WAAW,CAAC;CACd;AACF,CAAC"}
|