@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.
94 lines (93 loc) • 4.66 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import { createComponent } from '@workday/canvas-kit-react/common';
import { createStencil, handleCsProp, px2rem } from '@workday/canvas-kit-styling';
import { system } from '@workday/canvas-tokens-web';
import { SidePanelContext } from './hooks';
import { SidePanelToggleButton } from './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.
*/
export const panelStencil = 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.
*/
export const SidePanel = 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 (_jsx(Element, { ref: ref, onTransitionEnd: handleAnimationEnd, ...handleCsProp(elemProps, [
panelStencil({
expanded,
variant,
expandedWidth: typeof expandedWidth === 'number' ? px2rem(expandedWidth) : expandedWidth,
collapsedWidth: typeof collapsedWidth === 'number' ? px2rem(collapsedWidth) : collapsedWidth,
}),
]), children: _jsx(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,
},
});