UNPKG

@workday/canvas-kit-preview-react

Version:

Canvas Kit Preview is made up of components that have the full design and a11y review, are part of the DS ecosystem and are approved for use in product. The API's could be subject to change, but not without strong communication and migration strategies.

120 lines (119 loc) 6.01 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SidePanel = exports.panelStencil = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const React = __importStar(require("react")); const common_1 = require("@workday/canvas-kit-react/common"); const canvas_kit_styling_1 = require("@workday/canvas-kit-styling"); const canvas_tokens_web_1 = require("@workday/canvas-tokens-web"); const hooks_1 = require("./hooks"); const SidePanelToggleButton_1 = require("./SidePanelToggleButton"); /** * @deprecated ⚠️ `panelStencil` in Preview has been deprecated and will be removed in a future major version. Please use [`SidePanel` in Labs](https://workday.github.io/canvas-kit/?path=/docs/labs-side-panel--docs) instead. */ exports.panelStencil = (0, canvas_kit_styling_1.createStencil)({ vars: { expandedWidth: '', collapsedWidth: '', }, base: { name: "289euc", styles: "box-sizing:border-box;overflow:hidden;position:relative;height:100%;outline:0.0625rem solid transparent;transition:width ease-out 200ms, max-width ease-out 200ms;" }, modifiers: { variant: { alternate: { name: "2ljws2", styles: "background-color:var(--cnvs-sys-color-bg-default);box-shadow:var(--cnvs-sys-depth-5);" }, standard: { name: "40i1hk", styles: "background-color:var(--cnvs-sys-color-bg-alt-softer);" } }, expanded: { true: { name: "s3vmn", styles: "width:var(--expandedWidth-panel-8771e1);max-width:var(--expandedWidth-panel-8771e1);" }, false: { name: "2mo3no", styles: "width:var(--collapsedWidth-panel-8771e1);max-width:var(--collapsedWidth-panel-8771e1);" } }, touched: { true: { name: "3rydh7", styles: "" }, false: { name: "232d6w", styles: "animation:none;" } } } }, "panel-8771e1"); /** * @deprecated ⚠️ `SidePanel` in Preview has been deprecated and will be removed in a future major version. Please use [`SidePanel` in Labs](https://workday.github.io/canvas-kit/?path=/docs/labs-side-panel--docs) instead. */ exports.SidePanel = (0, common_1.createComponent)('section')({ displayName: 'SidePanel', Component({ children, collapsedWidth = 64, expanded = true, expandedWidth = 320, onAnimationEnd, onExpandedChange, onStateTransition, origin = 'left', variant = 'standard', touched, ...elemProps }, ref, Element) { const [state, setState] = React.useState(expanded ? 'expanded' : 'collapsed'); React.useEffect(() => { if (typeof onExpandedChange !== 'undefined') { onExpandedChange(expanded); } }, [expanded, onExpandedChange]); React.useEffect(() => { if (typeof onStateTransition !== 'undefined') { onStateTransition(state); } }, [state, onStateTransition]); const handleAnimationEnd = (event) => { if (event.propertyName === 'width') { if (state === 'expanding') { setState('expanded'); } else if (state === 'collapsing') { setState('collapsed'); } } }; const handleAnimationStart = () => { if (state === 'collapsed' || state === 'collapsing') { setState('expanding'); } else if (state === 'expanded' || state === 'expanding') { setState('collapsing'); } return undefined; }; return ((0, jsx_runtime_1.jsx)(Element, { ref: ref, onTransitionEnd: handleAnimationEnd, ...(0, canvas_kit_styling_1.handleCsProp)(elemProps, [ (0, exports.panelStencil)({ expanded, variant, expandedWidth: typeof expandedWidth === 'number' ? (0, canvas_kit_styling_1.px2rem)(expandedWidth) : expandedWidth, collapsedWidth: typeof collapsedWidth === 'number' ? (0, canvas_kit_styling_1.px2rem)(collapsedWidth) : collapsedWidth, }), ]), children: (0, jsx_runtime_1.jsx)(hooks_1.SidePanelContext.Provider, { value: { state, origin, handleAnimationStart, }, children: children }) })); }, subComponents: { /** * `SidePanel.ToggleButton` is a control that is meant to toggle between `expanded = true` and * `expanded = false` states. It must be used within the `SidePanel` component as a child. Use * in conjunction with `useSidePanel`'s `controlProps`, otherwise it does not come with explicit * `onClick` handlers. * * For accessibility purposes, it must be the first focusable element. We recommend that you * keep it as the first child of `SidePanel` */ ToggleButton: SidePanelToggleButton_1.SidePanelToggleButton, }, });