@mattermost/compass-ui 0.1.0-alpha.14 → 0.1.0-alpha.15
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/dist/components/action-button/ActionButton.cjs +1 -1
- package/dist/components/action-button/ActionButton.cjs.map +1 -1
- package/dist/components/action-button/ActionButton.css +1 -1
- package/dist/components/action-button/ActionButton.d.ts +41 -5
- package/dist/components/action-button/ActionButton.d.ts.map +1 -1
- package/dist/components/action-button/ActionButton.js +68 -35
- package/dist/components/action-button/ActionButton.js.map +1 -1
- package/dist/components/action-button/ActionButton.module.scss.cjs +1 -1
- package/dist/components/action-button/ActionButton.module.scss.js +6 -5
- package/dist/components/action-button/ActionButton.module.scss.js.map +1 -1
- package/dist/components/action-button/index.d.ts +1 -1
- package/dist/components/action-button/index.d.ts.map +1 -1
- package/dist/components/button/Button.cjs +1 -1
- package/dist/components/button/Button.cjs.map +1 -1
- package/dist/components/button/Button.css +1 -1
- package/dist/components/button/Button.d.ts +37 -6
- package/dist/components/button/Button.d.ts.map +1 -1
- package/dist/components/button/Button.js +106 -44
- package/dist/components/button/Button.js.map +1 -1
- package/dist/components/button/Button.module.scss.cjs +1 -1
- package/dist/components/button/Button.module.scss.js +16 -15
- package/dist/components/button/Button.module.scss.js.map +1 -1
- package/dist/components/button/index.d.ts +1 -1
- package/dist/components/button/index.d.ts.map +1 -1
- package/dist/components/icon-button/IconButton.cjs +1 -1
- package/dist/components/icon-button/IconButton.cjs.map +1 -1
- package/dist/components/icon-button/IconButton.css +1 -1
- package/dist/components/icon-button/IconButton.d.ts +48 -7
- package/dist/components/icon-button/IconButton.d.ts.map +1 -1
- package/dist/components/icon-button/IconButton.js +136 -62
- package/dist/components/icon-button/IconButton.js.map +1 -1
- package/dist/components/icon-button/IconButton.module.scss.cjs +1 -1
- package/dist/components/icon-button/IconButton.module.scss.js +16 -15
- package/dist/components/icon-button/IconButton.module.scss.js.map +1 -1
- package/dist/components/icon-button/index.d.ts +1 -1
- package/dist/components/icon-button/index.d.ts.map +1 -1
- package/dist/components/right-sidebar-header/RightSidebarHeader.cjs +1 -1
- package/dist/components/right-sidebar-header/RightSidebarHeader.cjs.map +1 -1
- package/dist/components/right-sidebar-header/RightSidebarHeader.d.ts +5 -1
- package/dist/components/right-sidebar-header/RightSidebarHeader.d.ts.map +1 -1
- package/dist/components/right-sidebar-header/RightSidebarHeader.js +60 -48
- package/dist/components/right-sidebar-header/RightSidebarHeader.js.map +1 -1
- package/dist/utils/slot.cjs +2 -0
- package/dist/utils/slot.cjs.map +1 -0
- package/dist/utils/slot.d.ts +46 -0
- package/dist/utils/slot.d.ts.map +1 -0
- package/dist/utils/slot.js +88 -0
- package/dist/utils/slot.js.map +1 -0
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RightSidebarHeader.js","sources":["../../../src/components/right-sidebar-header/RightSidebarHeader.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport ArrowBackIosIcon from '@mattermost/compass-icons/components/arrow-back-ios';\nimport ArrowCollapseIcon from '@mattermost/compass-icons/components/arrow-collapse';\nimport ArrowExpandIcon from '@mattermost/compass-icons/components/arrow-expand';\nimport CloseIcon from '@mattermost/compass-icons/components/close';\nimport Icon from '@/components/icon/Icon';\nimport IconButton from '@/components/icon-button/IconButton';\nimport Tag from '@/components/tag/Tag';\nimport type { TagType } from '@/components/tag/Tag';\nimport styles from './RightSidebarHeader.module.scss';\n\nexport interface RightSidebarHeaderProps {\n /** Primary title text. Accepts translated nodes (e.g. `<FormattedMessage/>`). */\n title: ReactNode;\n /** Secondary title shown to the right of a vertical divider (e.g. parent channel name). */\n secondaryTitle?: ReactNode;\n /** Optional tag rendered next to the title (e.g. \"BETA\"). */\n tag?: ReactNode;\n /** Tag visual style. Default: Info. */\n tagType?: TagType;\n /** Optional leading element shown before the title — typically a `UserAvatar` or an icon. When passing an icon, use `<Icon glyph={<SomeIcon />} size=\"20\" />` to align with the title text. */\n leadingIcon?: ReactNode;\n /** When set, shows a back button and calls this on click. */\n onBack?: () => void;\n /** Accessible name for the back button. Default: \"Back\". */\n backLabel?: string;\n /** When set, shows an expand/collapse button and calls this on click. */\n onExpand?: () => void;\n /** When true, the expand button shows the collapse icon. Requires `onExpand`. */\n expanded?: boolean;\n /** Accessible name for the expand button while collapsed. Default: \"Expand\". */\n expandLabel?: string;\n /** Accessible name for the expand button while expanded. Default: \"Collapse\". */\n collapseLabel?: string;\n /** When set, shows a close button and calls this on click. */\n onClose?: () => void;\n /** Accessible name for the close button. Default: \"Close\". */\n closeLabel?: string;\n /** Optional inline action label (e.g. \"Follow\"). Accepts translated nodes. */\n actionLabel?: ReactNode;\n /** Click handler for the action label. */\n onActionClick?: () => void;\n /** When true, the action button shows in its active state. */\n actionActive?: boolean;\n className?: string;\n}\n\nexport default function RightSidebarHeader({\n title,\n secondaryTitle,\n tag,\n tagType = 'info',\n leadingIcon,\n onBack,\n backLabel = 'Back',\n onExpand,\n expanded = false,\n expandLabel = 'Expand',\n collapseLabel = 'Collapse',\n onClose,\n closeLabel = 'Close',\n actionLabel,\n onActionClick,\n actionActive = false,\n className = '',\n}: RightSidebarHeaderProps) {\n const rootClass = [styles['right-sidebar-header'], className]\n .filter(Boolean)\n .join(' ');\n\n return (\n <div className={rootClass}>\n <div className={styles['right-sidebar-header__left']}>\n <div className={styles['right-sidebar-header__primary']}>\n {onBack && (\n <IconButton\n className={styles['right-sidebar-header__back']}\n size=\"small\"\n aria-label={backLabel}\n onClick={onBack}\n icon={<Icon size=\"16\" glyph={<ArrowBackIosIcon />} />}\n />\n )}\n {leadingIcon && (\n <span className={styles['right-sidebar-header__leading-icon']}>\n {leadingIcon}\n </span>\n )}\n <span className={styles['right-sidebar-header__title']}>{title}</span>\n {tag && (\n <span className={styles['right-sidebar-header__tag']}>\n <Tag\n label={tag}\n type={tagType}\n size=\"x-small\"\n casing=\"all-caps\"\n />\n </span>\n )}\n </div>\n {secondaryTitle && (\n <div className={styles['right-sidebar-header__secondary']}>\n <span className={styles['right-sidebar-header__secondary-text']}>\n {secondaryTitle}\n </span>\n </div>\n )}\n </div>\n\n <div className={styles['right-sidebar-header__actions']}>\n {actionLabel && (\n <button\n type=\"button\"\n className={[\n styles['right-sidebar-header__action'],\n actionActive\n ? styles['right-sidebar-header__action--active']\n : '',\n ]\n .filter(Boolean)\n .join(' ')}\n onClick={onActionClick}\n aria-pressed={actionActive ? true : undefined}\n >\n {actionLabel}\n </button>\n )}\n {onExpand && (\n <IconButton\n size=\"small\"\n aria-label={expanded ? collapseLabel : expandLabel}\n onClick={onExpand}\n icon={\n <Icon\n size=\"16\"\n glyph={expanded ? <ArrowCollapseIcon /> : <ArrowExpandIcon />}\n />\n }\n />\n )}\n {onClose && (\n <IconButton\n size=\"small\"\n aria-label={closeLabel}\n onClick={onClose}\n icon={<Icon size=\"16\" glyph={<CloseIcon />} />}\n />\n )}\n </div>\n </div>\n );\n}\n"],"names":["RightSidebarHeader","title","secondaryTitle","tag","tagType","leadingIcon","onBack","backLabel","onExpand","expanded","expandLabel","collapseLabel","onClose","closeLabel","actionLabel","onActionClick","actionActive","className","rootClass","styles","jsxs","jsx","IconButton","Icon","ArrowBackIosIcon","Tag","ArrowCollapseIcon","ArrowExpandIcon","CloseIcon"],"mappings":"
|
|
1
|
+
{"version":3,"file":"RightSidebarHeader.js","sources":["../../../src/components/right-sidebar-header/RightSidebarHeader.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport ArrowBackIosIcon from '@mattermost/compass-icons/components/arrow-back-ios';\nimport ArrowCollapseIcon from '@mattermost/compass-icons/components/arrow-collapse';\nimport ArrowExpandIcon from '@mattermost/compass-icons/components/arrow-expand';\nimport CloseIcon from '@mattermost/compass-icons/components/close';\nimport DockWindowIcon from '@mattermost/compass-icons/components/dock-window';\nimport Icon from '@/components/icon/Icon';\nimport IconButton from '@/components/icon-button/IconButton';\nimport Tag from '@/components/tag/Tag';\nimport type { TagType } from '@/components/tag/Tag';\nimport styles from './RightSidebarHeader.module.scss';\n\nexport interface RightSidebarHeaderProps {\n /** Primary title text. Accepts translated nodes (e.g. `<FormattedMessage/>`). */\n title: ReactNode;\n /** Secondary title shown to the right of a vertical divider (e.g. parent channel name). */\n secondaryTitle?: ReactNode;\n /** Optional tag rendered next to the title (e.g. \"BETA\"). */\n tag?: ReactNode;\n /** Tag visual style. Default: Info. */\n tagType?: TagType;\n /** Optional leading element shown before the title — typically a `UserAvatar` or an icon. When passing an icon, use `<Icon glyph={<SomeIcon />} size=\"20\" />` to align with the title text. */\n leadingIcon?: ReactNode;\n /** When set, shows a back button and calls this on click. */\n onBack?: () => void;\n /** Accessible name for the back button. Default: \"Back\". */\n backLabel?: string;\n /** When set, shows an expand/collapse button and calls this on click. */\n onExpand?: () => void;\n /** When true, the expand button shows the collapse icon. Requires `onExpand`. */\n expanded?: boolean;\n /** Accessible name for the expand button while collapsed. Default: \"Expand\". */\n expandLabel?: string;\n /** Accessible name for the expand button while expanded. Default: \"Collapse\". */\n collapseLabel?: string;\n /** When set, shows a pop out button (open in a new window) between expand and close, and calls this on click. */\n onPopout?: () => void;\n /** Accessible name for the pop out button. Default: \"Open in new window\". */\n popoutLabel?: string;\n /** When set, shows a close button and calls this on click. */\n onClose?: () => void;\n /** Accessible name for the close button. Default: \"Close\". */\n closeLabel?: string;\n /** Optional inline action label (e.g. \"Follow\"). Accepts translated nodes. */\n actionLabel?: ReactNode;\n /** Click handler for the action label. */\n onActionClick?: () => void;\n /** When true, the action button shows in its active state. */\n actionActive?: boolean;\n className?: string;\n}\n\nexport default function RightSidebarHeader({\n title,\n secondaryTitle,\n tag,\n tagType = 'info',\n leadingIcon,\n onBack,\n backLabel = 'Back',\n onExpand,\n expanded = false,\n expandLabel = 'Expand',\n collapseLabel = 'Collapse',\n onPopout,\n popoutLabel = 'Open in new window',\n onClose,\n closeLabel = 'Close',\n actionLabel,\n onActionClick,\n actionActive = false,\n className = '',\n}: RightSidebarHeaderProps) {\n const rootClass = [styles['right-sidebar-header'], className]\n .filter(Boolean)\n .join(' ');\n\n return (\n <div className={rootClass}>\n <div className={styles['right-sidebar-header__left']}>\n <div className={styles['right-sidebar-header__primary']}>\n {onBack && (\n <IconButton\n className={styles['right-sidebar-header__back']}\n size=\"small\"\n aria-label={backLabel}\n onClick={onBack}\n icon={<Icon size=\"16\" glyph={<ArrowBackIosIcon />} />}\n />\n )}\n {leadingIcon && (\n <span className={styles['right-sidebar-header__leading-icon']}>\n {leadingIcon}\n </span>\n )}\n <span className={styles['right-sidebar-header__title']}>{title}</span>\n {tag && (\n <span className={styles['right-sidebar-header__tag']}>\n <Tag\n label={tag}\n type={tagType}\n size=\"x-small\"\n casing=\"all-caps\"\n />\n </span>\n )}\n </div>\n {secondaryTitle && (\n <div className={styles['right-sidebar-header__secondary']}>\n <span className={styles['right-sidebar-header__secondary-text']}>\n {secondaryTitle}\n </span>\n </div>\n )}\n </div>\n\n <div className={styles['right-sidebar-header__actions']}>\n {actionLabel && (\n <button\n type=\"button\"\n className={[\n styles['right-sidebar-header__action'],\n actionActive\n ? styles['right-sidebar-header__action--active']\n : '',\n ]\n .filter(Boolean)\n .join(' ')}\n onClick={onActionClick}\n aria-pressed={actionActive ? true : undefined}\n >\n {actionLabel}\n </button>\n )}\n {onExpand && (\n <IconButton\n size=\"small\"\n aria-label={expanded ? collapseLabel : expandLabel}\n onClick={onExpand}\n icon={\n <Icon\n size=\"16\"\n glyph={expanded ? <ArrowCollapseIcon /> : <ArrowExpandIcon />}\n />\n }\n />\n )}\n {onPopout && (\n <IconButton\n size=\"small\"\n aria-label={popoutLabel}\n onClick={onPopout}\n icon={<Icon size=\"16\" glyph={<DockWindowIcon />} />}\n />\n )}\n {onClose && (\n <IconButton\n size=\"small\"\n aria-label={closeLabel}\n onClick={onClose}\n icon={<Icon size=\"16\" glyph={<CloseIcon />} />}\n />\n )}\n </div>\n </div>\n );\n}\n"],"names":["RightSidebarHeader","title","secondaryTitle","tag","tagType","leadingIcon","onBack","backLabel","onExpand","expanded","expandLabel","collapseLabel","onPopout","popoutLabel","onClose","closeLabel","actionLabel","onActionClick","actionActive","className","rootClass","styles","jsxs","jsx","IconButton","Icon","ArrowBackIosIcon","Tag","ArrowCollapseIcon","ArrowExpandIcon","DockWindowIcon","CloseIcon"],"mappings":";;;;;;;;;;AAoDA,SAAwBA,EAAmB;AAAA,EACzC,OAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,KAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,aAAAC;AAAA,EACA,QAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,aAAAC,IAAc;AAAA,EACd,eAAAC,IAAgB;AAAA,EAChB,UAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,SAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,aAAAC;AAAA,EACA,eAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,WAAAC,IAAY;AACd,GAA4B;AAC1B,QAAMC,IAAY,CAACC,EAAO,sBAAsB,GAAGF,CAAS,EACzD,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,SACE,gBAAAG,EAAC,OAAA,EAAI,WAAWF,GACd,UAAA;AAAA,IAAA,gBAAAE,EAAC,OAAA,EAAI,WAAWD,EAAO,4BAA4B,GACjD,UAAA;AAAA,MAAA,gBAAAC,EAAC,OAAA,EAAI,WAAWD,EAAO,+BAA+B,GACnD,UAAA;AAAA,QAAAf,KACC,gBAAAiB;AAAA,UAACC;AAAA,UAAA;AAAA,YACC,WAAWH,EAAO,4BAA4B;AAAA,YAC9C,MAAK;AAAA,YACL,cAAYd;AAAA,YACZ,SAASD;AAAA,YACT,wBAAOmB,GAAA,EAAK,MAAK,MAAK,OAAO,gBAAAF,EAACG,KAAiB,EAAA,CAAI;AAAA,UAAA;AAAA,QAAA;AAAA,QAGtDrB,KACC,gBAAAkB,EAAC,QAAA,EAAK,WAAWF,EAAO,oCA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AAA,UACC,MAAK;AAAA,UACL,cAAYX;AAAA,UACZ,SAASD;AAAA,UACT,wBAAOa,GAAA,EAAK,MAAK,MAAK,OAAO,gBAAAF,EAACO,KAAe,EAAA,CAAI;AAAA,QAAA;AAAA,MAAA;AAAA,MAGpDhB,KACC,gBAAAS;AAAA,QAACC;AAAA,QAAA;AAAA,UACC,MAAK;AAAA,UACL,cAAYT;AAAA,UACZ,SAASD;AAAA,UACT,wBAAOW,GAAA,EAAK,MAAK,MAAK,OAAO,gBAAAF,EAACQ,KAAU,EAAA,CAAI;AAAA,QAAA;AAAA,MAAA;AAAA,IAC9C,EAAA,CAEJ;AAAA,EAAA,GACF;AAEJ;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),d=require("./props.cjs");function R(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function y(...e){return t=>{for(const n of e)R(n,t)}}function g(e){var n;const t=(n=e.props)==null?void 0:n.ref;return t!==void 0?t:e.ref}function v(e){var t;return e.length>2&&e.startsWith("on")&&e[2]===((t=e[2])==null?void 0:t.toUpperCase())}function h(e,t){const n={...t};for(const r of Object.keys(e)){const o=e[r],s=t[r];v(r)?typeof o=="function"&&typeof s=="function"?n[r]=(...c)=>{const l=c[0];s(...c),l!=null&&l.defaultPrevented||o(...c)}:typeof o=="function"&&(n[r]=o):r==="style"?n.style={...typeof o=="object"&&o!=null?o:null,...typeof s=="object"&&s!=null?s:null}:r==="className"?n.className=d.mergeClassNames(typeof o=="string"?o:void 0,typeof s=="string"?s:void 0):r in t||(n[r]=o)}return n}function C(e){return e==null||e===!1||e===!0?!1:typeof e=="string"?e.length>0:Array.isArray(e)?e.some(C):!0}function m(e){e.preventDefault(),e.stopPropagation()}function b({child:e,props:t,ref:n,content:r,disabled:o=!1,disabledClassName:s,warnOnChildContent:c=!1}){const l=process.env.NODE_ENV!=="production";let i=null;try{i=u.Children.only(e)}catch{i=null}if(!u.isValidElement(i))return l&&console.warn("asChild expects a single React element child (e.g. <a> or <Link>)."),null;const p=i.props;l&&c&&C(p.children)&&console.warn(`asChild replaces the child element's children with component anatomy. Pass an empty element (e.g. <a href="…" />).`);const f={...t};delete f.type,o&&(f["aria-disabled"]=!0,s&&(f.className=d.mergeClassNames(typeof f.className=="string"?f.className:void 0,s)));const a=h(f,p);o&&(a.onClick=m,a.onAuxClick=m);const N=g(i);return u.cloneElement(i,{...a,ref:y(n,N),children:r})}exports.composeRefs=y;exports.getElementRef=g;exports.mergeSlotProps=h;exports.renderAsChild=b;
|
|
2
|
+
//# sourceMappingURL=slot.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot.cjs","sources":["../../src/utils/slot.ts"],"sourcesContent":["import {\n Children,\n cloneElement,\n isValidElement,\n type CSSProperties,\n type ReactElement,\n type ReactNode,\n type Ref,\n type RefCallback,\n} from 'react';\nimport { mergeClassNames } from '@/utils/props';\n\ntype PossibleRef<T> = Ref<T> | undefined;\n\n/** Assigns a value to a callback or object ref. */\nfunction setRef<T>(ref: PossibleRef<T>, value: T | null) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref != null) {\n (ref as { current: T | null }).current = value;\n }\n}\n\n/** Composes multiple refs into a single callback ref. */\nexport function composeRefs<T>(...refs: Array<PossibleRef<T>>): RefCallback<T> {\n return (node) => {\n for (const ref of refs) {\n setRef(ref, node);\n }\n };\n}\n\n/**\n * Reads the ref from a React element across React 18 (`element.ref`) and\n * React 19 (`element.props.ref`).\n */\nexport function getElementRef(element: ReactElement): Ref<unknown> | undefined {\n // React 19: ref is a regular prop. React 18: ref is on the element.\n const propsRef = (element.props as { ref?: Ref<unknown> } | null | undefined)\n ?.ref;\n if (propsRef !== undefined) {\n return propsRef;\n }\n return (element as ReactElement & { ref?: Ref<unknown> }).ref;\n}\n\ntype AnyProps = Record<string, unknown>;\n\nfunction isHandlerKey(key: string): boolean {\n return (\n key.length > 2 && key.startsWith('on') && key[2] === key[2]?.toUpperCase()\n );\n}\n\n/**\n * Merges Slot (asChild host) props with the child's props.\n * Child props win by default; event handlers are composed (child first;\n * host skipped when the child called `preventDefault()`); `className` and\n * `style` are merged.\n */\nexport function mergeSlotProps(\n slotProps: AnyProps,\n childProps: AnyProps,\n): AnyProps {\n const override: AnyProps = { ...childProps };\n\n for (const propName of Object.keys(slotProps)) {\n const slotValue = slotProps[propName];\n const childValue = childProps[propName];\n\n if (isHandlerKey(propName)) {\n if (typeof slotValue === 'function' && typeof childValue === 'function') {\n override[propName] = (...args: unknown[]) => {\n const event = args[0] as { defaultPrevented?: boolean } | undefined;\n childValue(...args);\n if (!event?.defaultPrevented) {\n slotValue(...args);\n }\n };\n } else if (typeof slotValue === 'function') {\n override[propName] = slotValue;\n }\n } else if (propName === 'style') {\n override.style = {\n ...(typeof slotValue === 'object' && slotValue != null\n ? (slotValue as CSSProperties)\n : null),\n ...(typeof childValue === 'object' && childValue != null\n ? (childValue as CSSProperties)\n : null),\n };\n } else if (propName === 'className') {\n override.className = mergeClassNames(\n typeof slotValue === 'string' ? slotValue : undefined,\n typeof childValue === 'string' ? childValue : undefined,\n );\n } else if (!(propName in childProps)) {\n override[propName] = slotValue;\n }\n }\n\n return override;\n}\n\nfunction hasRenderableChildren(children: ReactNode): boolean {\n if (children == null || children === false || children === true) {\n return false;\n }\n if (typeof children === 'string') {\n return children.length > 0;\n }\n if (Array.isArray(children)) {\n return children.some(hasRenderableChildren);\n }\n return true;\n}\n\nfunction blockNavigation(event: {\n preventDefault: () => void;\n stopPropagation: () => void;\n}) {\n event.preventDefault();\n event.stopPropagation();\n}\n\nexport interface RenderAsChildOptions {\n /** Single React element to clone (e.g. `<a>` or `<Link>`). */\n child: ReactNode;\n /** Props owned by the host component (className, handlers, aria-*, …). */\n props: AnyProps;\n /** Forwarded ref from the host. */\n ref?: Ref<unknown>;\n /** Anatomy nodes that replace the child's children. */\n content: ReactNode;\n /** When true, apply disabled-link semantics. */\n disabled?: boolean;\n /** BEM disabled class (e.g. `button--disabled`). */\n disabledClassName?: string;\n /**\n * When true, warn in development if the child already has children (they\n * will be replaced). Use for hosts that own their full anatomy\n * (IconButton, ActionButton). Leave false when the host wraps the child's\n * text (Button label).\n */\n warnOnChildContent?: boolean;\n}\n\n/**\n * Clones a single child element with merged host props, composed refs, and\n * replacement content. Never forwards `type`. When `disabled`, sets\n * `aria-disabled`, the disabled class, and blocks click / auxclick navigation.\n */\nexport function renderAsChild({\n child,\n props,\n ref,\n content,\n disabled = false,\n disabledClassName,\n warnOnChildContent = false,\n}: RenderAsChildOptions): ReactElement | null {\n const warn = process.env.NODE_ENV !== 'production';\n\n let onlyChild: ReactNode = null;\n try {\n onlyChild = Children.only(child);\n } catch {\n onlyChild = null;\n }\n\n if (!isValidElement(onlyChild)) {\n if (warn) {\n console.warn(\n 'asChild expects a single React element child (e.g. <a> or <Link>).',\n );\n }\n return null;\n }\n\n const childProps = onlyChild.props as AnyProps & { children?: ReactNode };\n\n if (\n warn &&\n warnOnChildContent &&\n hasRenderableChildren(childProps.children)\n ) {\n console.warn(\n 'asChild replaces the child element\\'s children with component anatomy. Pass an empty element (e.g. <a href=\"…\" />).',\n );\n }\n\n // Strip `type` — on <a> it means MIME type, not button type.\n const slotProps: AnyProps = { ...props };\n delete slotProps.type;\n\n if (disabled) {\n slotProps['aria-disabled'] = true;\n if (disabledClassName) {\n slotProps.className = mergeClassNames(\n typeof slotProps.className === 'string'\n ? slotProps.className\n : undefined,\n disabledClassName,\n );\n }\n }\n\n const merged = mergeSlotProps(slotProps, childProps);\n\n if (disabled) {\n merged.onClick = blockNavigation;\n merged.onAuxClick = blockNavigation;\n }\n\n const childRef = getElementRef(onlyChild);\n\n return cloneElement(onlyChild, {\n ...merged,\n ref: composeRefs(ref, childRef),\n children: content,\n } as AnyProps);\n}\n"],"names":["setRef","ref","value","composeRefs","refs","node","getElementRef","element","propsRef","_a","isHandlerKey","key","mergeSlotProps","slotProps","childProps","override","propName","slotValue","childValue","args","event","mergeClassNames","hasRenderableChildren","children","blockNavigation","renderAsChild","child","props","content","disabled","disabledClassName","warnOnChildContent","warn","onlyChild","Children","isValidElement","merged","childRef","cloneElement"],"mappings":"kIAeA,SAASA,EAAUC,EAAqBC,EAAiB,CACnD,OAAOD,GAAQ,WACjBA,EAAIC,CAAK,EACAD,GAAO,OACfA,EAA8B,QAAUC,EAE7C,CAGO,SAASC,KAAkBC,EAA6C,CAC7E,OAAQC,GAAS,CACf,UAAWJ,KAAOG,EAChBJ,EAAOC,EAAKI,CAAI,CAEpB,CACF,CAMO,SAASC,EAAcC,EAAiD,OAE7E,MAAMC,GAAYC,EAAAF,EAAQ,QAAR,YAAAE,EACd,IACJ,OAAID,IAAa,OACRA,EAEDD,EAAkD,GAC5D,CAIA,SAASG,EAAaC,EAAsB,OAC1C,OACEA,EAAI,OAAS,GAAKA,EAAI,WAAW,IAAI,GAAKA,EAAI,CAAC,MAAMF,EAAAE,EAAI,CAAC,IAAL,YAAAF,EAAQ,cAEjE,CAQO,SAASG,EACdC,EACAC,EACU,CACV,MAAMC,EAAqB,CAAE,GAAGD,CAAA,EAEhC,UAAWE,KAAY,OAAO,KAAKH,CAAS,EAAG,CAC7C,MAAMI,EAAYJ,EAAUG,CAAQ,EAC9BE,EAAaJ,EAAWE,CAAQ,EAElCN,EAAaM,CAAQ,EACnB,OAAOC,GAAc,YAAc,OAAOC,GAAe,WAC3DH,EAASC,CAAQ,EAAI,IAAIG,IAAoB,CAC3C,MAAMC,EAAQD,EAAK,CAAC,EACpBD,EAAW,GAAGC,CAAI,EACbC,GAAA,MAAAA,EAAO,kBACVH,EAAU,GAAGE,CAAI,CAErB,EACS,OAAOF,GAAc,aAC9BF,EAASC,CAAQ,EAAIC,GAEdD,IAAa,QACtBD,EAAS,MAAQ,CACf,GAAI,OAAOE,GAAc,UAAYA,GAAa,KAC7CA,EACD,KACJ,GAAI,OAAOC,GAAe,UAAYA,GAAc,KAC/CA,EACD,IAAA,EAEGF,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AaL,EAAW,CAC7B,GAAGG,EACH,IAAKjC,EAAYF,EAAKoC,CAAQ,EAC9B,SAAUT,CAAA,CACC,CACf"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ReactElement, ReactNode, Ref, RefCallback } from 'react';
|
|
2
|
+
type PossibleRef<T> = Ref<T> | undefined;
|
|
3
|
+
/** Composes multiple refs into a single callback ref. */
|
|
4
|
+
export declare function composeRefs<T>(...refs: Array<PossibleRef<T>>): RefCallback<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Reads the ref from a React element across React 18 (`element.ref`) and
|
|
7
|
+
* React 19 (`element.props.ref`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function getElementRef(element: ReactElement): Ref<unknown> | undefined;
|
|
10
|
+
type AnyProps = Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Merges Slot (asChild host) props with the child's props.
|
|
13
|
+
* Child props win by default; event handlers are composed (child first;
|
|
14
|
+
* host skipped when the child called `preventDefault()`); `className` and
|
|
15
|
+
* `style` are merged.
|
|
16
|
+
*/
|
|
17
|
+
export declare function mergeSlotProps(slotProps: AnyProps, childProps: AnyProps): AnyProps;
|
|
18
|
+
export interface RenderAsChildOptions {
|
|
19
|
+
/** Single React element to clone (e.g. `<a>` or `<Link>`). */
|
|
20
|
+
child: ReactNode;
|
|
21
|
+
/** Props owned by the host component (className, handlers, aria-*, …). */
|
|
22
|
+
props: AnyProps;
|
|
23
|
+
/** Forwarded ref from the host. */
|
|
24
|
+
ref?: Ref<unknown>;
|
|
25
|
+
/** Anatomy nodes that replace the child's children. */
|
|
26
|
+
content: ReactNode;
|
|
27
|
+
/** When true, apply disabled-link semantics. */
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
/** BEM disabled class (e.g. `button--disabled`). */
|
|
30
|
+
disabledClassName?: string;
|
|
31
|
+
/**
|
|
32
|
+
* When true, warn in development if the child already has children (they
|
|
33
|
+
* will be replaced). Use for hosts that own their full anatomy
|
|
34
|
+
* (IconButton, ActionButton). Leave false when the host wraps the child's
|
|
35
|
+
* text (Button label).
|
|
36
|
+
*/
|
|
37
|
+
warnOnChildContent?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Clones a single child element with merged host props, composed refs, and
|
|
41
|
+
* replacement content. Never forwards `type`. When `disabled`, sets
|
|
42
|
+
* `aria-disabled`, the disabled class, and blocks click / auxclick navigation.
|
|
43
|
+
*/
|
|
44
|
+
export declare function renderAsChild({ child, props, ref, content, disabled, disabledClassName, warnOnChildContent, }: RenderAsChildOptions): ReactElement | null;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=slot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../src/utils/slot.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,GAAG,EACR,KAAK,WAAW,EACjB,MAAM,OAAO,CAAC;AAGf,KAAK,WAAW,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AAWzC,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAM7E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,SAAS,CAQ7E;AAED,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAQxC;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,QAAQ,EACnB,UAAU,EAAE,QAAQ,GACnB,QAAQ,CAuCV;AAuBD,MAAM,WAAW,oBAAoB;IACnC,8DAA8D;IAC9D,KAAK,EAAE,SAAS,CAAC;IACjB,0EAA0E;IAC1E,KAAK,EAAE,QAAQ,CAAC;IAChB,mCAAmC;IACnC,GAAG,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACnB,uDAAuD;IACvD,OAAO,EAAE,SAAS,CAAC;IACnB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,KAAK,EACL,GAAG,EACH,OAAO,EACP,QAAgB,EAChB,iBAAiB,EACjB,kBAA0B,GAC3B,EAAE,oBAAoB,GAAG,YAAY,GAAG,IAAI,CA6D5C"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Children as h, isValidElement as g, cloneElement as C } from "react";
|
|
2
|
+
import { mergeClassNames as m } from "./props.js";
|
|
3
|
+
function N(e, t) {
|
|
4
|
+
typeof e == "function" ? e(t) : e != null && (e.current = t);
|
|
5
|
+
}
|
|
6
|
+
function R(...e) {
|
|
7
|
+
return (t) => {
|
|
8
|
+
for (const n of e)
|
|
9
|
+
N(n, t);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function v(e) {
|
|
13
|
+
var n;
|
|
14
|
+
const t = (n = e.props) == null ? void 0 : n.ref;
|
|
15
|
+
return t !== void 0 ? t : e.ref;
|
|
16
|
+
}
|
|
17
|
+
function E(e) {
|
|
18
|
+
var t;
|
|
19
|
+
return e.length > 2 && e.startsWith("on") && e[2] === ((t = e[2]) == null ? void 0 : t.toUpperCase());
|
|
20
|
+
}
|
|
21
|
+
function b(e, t) {
|
|
22
|
+
const n = { ...t };
|
|
23
|
+
for (const r of Object.keys(e)) {
|
|
24
|
+
const o = e[r], l = t[r];
|
|
25
|
+
E(r) ? typeof o == "function" && typeof l == "function" ? n[r] = (...c) => {
|
|
26
|
+
const s = c[0];
|
|
27
|
+
l(...c), s != null && s.defaultPrevented || o(...c);
|
|
28
|
+
} : typeof o == "function" && (n[r] = o) : r === "style" ? n.style = {
|
|
29
|
+
...typeof o == "object" && o != null ? o : null,
|
|
30
|
+
...typeof l == "object" && l != null ? l : null
|
|
31
|
+
} : r === "className" ? n.className = m(
|
|
32
|
+
typeof o == "string" ? o : void 0,
|
|
33
|
+
typeof l == "string" ? l : void 0
|
|
34
|
+
) : r in t || (n[r] = o);
|
|
35
|
+
}
|
|
36
|
+
return n;
|
|
37
|
+
}
|
|
38
|
+
function y(e) {
|
|
39
|
+
return e == null || e === !1 || e === !0 ? !1 : typeof e == "string" ? e.length > 0 : Array.isArray(e) ? e.some(y) : !0;
|
|
40
|
+
}
|
|
41
|
+
function p(e) {
|
|
42
|
+
e.preventDefault(), e.stopPropagation();
|
|
43
|
+
}
|
|
44
|
+
function V({
|
|
45
|
+
child: e,
|
|
46
|
+
props: t,
|
|
47
|
+
ref: n,
|
|
48
|
+
content: r,
|
|
49
|
+
disabled: o = !1,
|
|
50
|
+
disabledClassName: l,
|
|
51
|
+
warnOnChildContent: c = !1
|
|
52
|
+
}) {
|
|
53
|
+
const s = process.env.NODE_ENV !== "production";
|
|
54
|
+
let i = null;
|
|
55
|
+
try {
|
|
56
|
+
i = h.only(e);
|
|
57
|
+
} catch {
|
|
58
|
+
i = null;
|
|
59
|
+
}
|
|
60
|
+
if (!g(i))
|
|
61
|
+
return s && console.warn(
|
|
62
|
+
"asChild expects a single React element child (e.g. <a> or <Link>)."
|
|
63
|
+
), null;
|
|
64
|
+
const u = i.props;
|
|
65
|
+
s && c && y(u.children) && console.warn(
|
|
66
|
+
`asChild replaces the child element's children with component anatomy. Pass an empty element (e.g. <a href="…" />).`
|
|
67
|
+
);
|
|
68
|
+
const f = { ...t };
|
|
69
|
+
delete f.type, o && (f["aria-disabled"] = !0, l && (f.className = m(
|
|
70
|
+
typeof f.className == "string" ? f.className : void 0,
|
|
71
|
+
l
|
|
72
|
+
)));
|
|
73
|
+
const a = b(f, u);
|
|
74
|
+
o && (a.onClick = p, a.onAuxClick = p);
|
|
75
|
+
const d = v(i);
|
|
76
|
+
return C(i, {
|
|
77
|
+
...a,
|
|
78
|
+
ref: R(n, d),
|
|
79
|
+
children: r
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
R as composeRefs,
|
|
84
|
+
v as getElementRef,
|
|
85
|
+
b as mergeSlotProps,
|
|
86
|
+
V as renderAsChild
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=slot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot.js","sources":["../../src/utils/slot.ts"],"sourcesContent":["import {\n Children,\n cloneElement,\n isValidElement,\n type CSSProperties,\n type ReactElement,\n type ReactNode,\n type Ref,\n type RefCallback,\n} from 'react';\nimport { mergeClassNames } from '@/utils/props';\n\ntype PossibleRef<T> = Ref<T> | undefined;\n\n/** Assigns a value to a callback or object ref. */\nfunction setRef<T>(ref: PossibleRef<T>, value: T | null) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref != null) {\n (ref as { current: T | null }).current = value;\n }\n}\n\n/** Composes multiple refs into a single callback ref. */\nexport function composeRefs<T>(...refs: Array<PossibleRef<T>>): RefCallback<T> {\n return (node) => {\n for (const ref of refs) {\n setRef(ref, node);\n }\n };\n}\n\n/**\n * Reads the ref from a React element across React 18 (`element.ref`) and\n * React 19 (`element.props.ref`).\n */\nexport function getElementRef(element: ReactElement): Ref<unknown> | undefined {\n // React 19: ref is a regular prop. React 18: ref is on the element.\n const propsRef = (element.props as { ref?: Ref<unknown> } | null | undefined)\n ?.ref;\n if (propsRef !== undefined) {\n return propsRef;\n }\n return (element as ReactElement & { ref?: Ref<unknown> }).ref;\n}\n\ntype AnyProps = Record<string, unknown>;\n\nfunction isHandlerKey(key: string): boolean {\n return (\n key.length > 2 && key.startsWith('on') && key[2] === key[2]?.toUpperCase()\n );\n}\n\n/**\n * Merges Slot (asChild host) props with the child's props.\n * Child props win by default; event handlers are composed (child first;\n * host skipped when the child called `preventDefault()`); `className` and\n * `style` are merged.\n */\nexport function mergeSlotProps(\n slotProps: AnyProps,\n childProps: AnyProps,\n): AnyProps {\n const override: AnyProps = { ...childProps };\n\n for (const propName of Object.keys(slotProps)) {\n const slotValue = slotProps[propName];\n const childValue = childProps[propName];\n\n if (isHandlerKey(propName)) {\n if (typeof slotValue === 'function' && typeof childValue === 'function') {\n override[propName] = (...args: unknown[]) => {\n const event = args[0] as { defaultPrevented?: boolean } | undefined;\n childValue(...args);\n if (!event?.defaultPrevented) {\n slotValue(...args);\n }\n };\n } else if (typeof slotValue === 'function') {\n override[propName] = slotValue;\n }\n } else if (propName === 'style') {\n override.style = {\n ...(typeof slotValue === 'object' && slotValue != null\n ? (slotValue as CSSProperties)\n : null),\n ...(typeof childValue === 'object' && childValue != null\n ? (childValue as CSSProperties)\n : null),\n };\n } else if (propName === 'className') {\n override.className = mergeClassNames(\n typeof slotValue === 'string' ? slotValue : undefined,\n typeof childValue === 'string' ? childValue : undefined,\n );\n } else if (!(propName in childProps)) {\n override[propName] = slotValue;\n }\n }\n\n return override;\n}\n\nfunction hasRenderableChildren(children: ReactNode): boolean {\n if (children == null || children === false || children === true) {\n return false;\n }\n if (typeof children === 'string') {\n return children.length > 0;\n }\n if (Array.isArray(children)) {\n return children.some(hasRenderableChildren);\n }\n return true;\n}\n\nfunction blockNavigation(event: {\n preventDefault: () => void;\n stopPropagation: () => void;\n}) {\n event.preventDefault();\n event.stopPropagation();\n}\n\nexport interface RenderAsChildOptions {\n /** Single React element to clone (e.g. `<a>` or `<Link>`). */\n child: ReactNode;\n /** Props owned by the host component (className, handlers, aria-*, …). */\n props: AnyProps;\n /** Forwarded ref from the host. */\n ref?: Ref<unknown>;\n /** Anatomy nodes that replace the child's children. */\n content: ReactNode;\n /** When true, apply disabled-link semantics. */\n disabled?: boolean;\n /** BEM disabled class (e.g. `button--disabled`). */\n disabledClassName?: string;\n /**\n * When true, warn in development if the child already has children (they\n * will be replaced). Use for hosts that own their full anatomy\n * (IconButton, ActionButton). Leave false when the host wraps the child's\n * text (Button label).\n */\n warnOnChildContent?: boolean;\n}\n\n/**\n * Clones a single child element with merged host props, composed refs, and\n * replacement content. Never forwards `type`. When `disabled`, sets\n * `aria-disabled`, the disabled class, and blocks click / auxclick navigation.\n */\nexport function renderAsChild({\n child,\n props,\n ref,\n content,\n disabled = false,\n disabledClassName,\n warnOnChildContent = false,\n}: RenderAsChildOptions): ReactElement | null {\n const warn = process.env.NODE_ENV !== 'production';\n\n let onlyChild: ReactNode = null;\n try {\n onlyChild = Children.only(child);\n } catch {\n onlyChild = null;\n }\n\n if (!isValidElement(onlyChild)) {\n if (warn) {\n console.warn(\n 'asChild expects a single React element child (e.g. <a> or <Link>).',\n );\n }\n return null;\n }\n\n const childProps = onlyChild.props as AnyProps & { children?: ReactNode };\n\n if (\n warn &&\n warnOnChildContent &&\n hasRenderableChildren(childProps.children)\n ) {\n console.warn(\n 'asChild replaces the child element\\'s children with component anatomy. Pass an empty element (e.g. <a href=\"…\" />).',\n );\n }\n\n // Strip `type` — on <a> it means MIME type, not button type.\n const slotProps: AnyProps = { ...props };\n delete slotProps.type;\n\n if (disabled) {\n slotProps['aria-disabled'] = true;\n if (disabledClassName) {\n slotProps.className = mergeClassNames(\n typeof slotProps.className === 'string'\n ? slotProps.className\n : undefined,\n disabledClassName,\n );\n }\n }\n\n const merged = mergeSlotProps(slotProps, childProps);\n\n if (disabled) {\n merged.onClick = blockNavigation;\n merged.onAuxClick = blockNavigation;\n }\n\n const childRef = getElementRef(onlyChild);\n\n return cloneElement(onlyChild, {\n ...merged,\n ref: composeRefs(ref, childRef),\n children: content,\n } as AnyProps);\n}\n"],"names":["setRef","ref","value","composeRefs","refs","node","getElementRef","element","propsRef","_a","isHandlerKey","key","mergeSlotProps","slotProps","childProps","override","propName","slotValue","childValue","args","event","mergeClassNames","hasRenderableChildren","children","blockNavigation","renderAsChild","child","props","content","disabled","disabledClassName","warnOnChildContent","warn","onlyChild","Children","isValidElement","merged","childRef","cloneElement"],"mappings":";;AAeA,SAASA,EAAUC,GAAqBC,GAAiB;AACvD,EAAI,OAAOD,KAAQ,aACjBA,EAAIC,CAAK,IACAD,KAAO,SACfA,EAA8B,UAAUC;AAE7C;AAGO,SAASC,KAAkBC,GAA6C;AAC7E,SAAO,CAACC,MAAS;AACf,eAAWJ,KAAOG;AAChB,MAAAJ,EAAOC,GAAKI,CAAI;AAAA,EAEpB;AACF;AAMO,SAASC,EAAcC,GAAiD;;AAE7E,QAAMC,KAAYC,IAAAF,EAAQ,UAAR,gBAAAE,EACd;AACJ,SAAID,MAAa,SACRA,IAEDD,EAAkD;AAC5D;AAIA,SAASG,EAAaC,GAAsB;;AAC1C,SACEA,EAAI,SAAS,KAAKA,EAAI,WAAW,IAAI,KAAKA,EAAI,CAAC,QAAMF,IAAAE,EAAI,CAAC,MAAL,gBAAAF,EAAQ;AAEjE;AAQO,SAASG,EACdC,GACAC,GACU;AACV,QAAMC,IAAqB,EAAE,GAAGD,EAAA;AAEhC,aAAWE,KAAY,OAAO,KAAKH,CAAS,GAAG;AAC7C,UAAMI,IAAYJ,EAAUG,CAAQ,GAC9BE,IAAaJ,EAAWE,CAAQ;AAEtC,IAAIN,EAAaM,CAAQ,IACnB,OAAOC,KAAc,cAAc,OAAOC,KAAe,aAC3DH,EAASC,CAAQ,IAAI,IAAIG,MAAoB;AAC3C,YAAMC,IAAQD,EAAK,CAAC;AACpB,MAAAD,EAAW,GAAGC,CAAI,GACbC,KAAA,QAAAA,EAAO,oBACVH,EAAU,GAAGE,CAAI;AAAA,IAErB,IACS,OAAOF,KAAc,eAC9BF,EAASC,CAAQ,IAAIC,KAEdD,MAAa,UACtBD,EAAS,QAAQ;AAAA,MACf,GAAI,OAAOE,KAAc,YAAYA,KAAa,OAC7CA,IACD;AAAA,MACJ,GAAI,OAAOC,KAAe,YAAYA,KAAc,OAC/CA,IACD;AAAA,IAAA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AAU;AAEnD,EAAIe,MACFO,EAAO,UAAUZ,GACjBY,EAAO,aAAaZ;AAGtB,QAAMa,IAAW/B,EAAc2B,CAAS;AAExC,SAAOK,EAAaL,GAAW;AAAA,IAC7B,GAAGG;AAAA,IACH,KAAKjC,EAAYF,GAAKoC,CAAQ;AAAA,IAC9B,UAAUT;AAAA,EAAA,CACC;AACf;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mattermost/compass-ui",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.15",
|
|
4
4
|
"description": "Compass design system UI components for Mattermost products",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"@vitejs/plugin-react": "^4.3.4",
|
|
82
82
|
"react": "^19.0.0",
|
|
83
83
|
"react-dom": "^19.0.0",
|
|
84
|
+
"react-router-dom": "^6.28.0",
|
|
84
85
|
"sass": "^1.83.4",
|
|
85
86
|
"simplebar-react": "^3.3.2",
|
|
86
87
|
"storybook": "^8.6.14",
|