@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.
61 lines (60 loc) • 3.36 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import { createComponent } from '@workday/canvas-kit-react/common';
import { TertiaryButton } from '@workday/canvas-kit-react/button';
import { transformationImportIcon } from '@workday/canvas-system-icons-web';
import { Tooltip } from '@workday/canvas-kit-react/tooltip';
import { SidePanelContext } from './hooks';
import { createStencil, handleCsProp } from '@workday/canvas-kit-styling';
import { system } from '@workday/canvas-tokens-web';
export const sidePanelToggleButtonStencil = createStencil({
base: { name: "1ld29r", styles: "box-sizing:border-box;position:absolute;top:var(--cnvs-sys-space-x6);width:var(--cnvs-sys-space-x8);inset-inline-end:var(--cnvs-sys-space-x4);" },
modifiers: {
state: {
collapsing: { name: "332xq9", styles: "margin:0;transform:scaleX(1);:dir(rtl){transform:scaleX(-1);}" },
collapsed: { name: "27f1bp", styles: "margin:auto;inset-inline-start:0;inset-inline-end:0;transform:scaleX(1);:dir(rtl){transform:scaleX(-1);}" },
expanded: { name: "2h3lso", styles: "margin:0;transform:scaleX(-1);:dir(rtl){transform:scaleX(1);}" },
expanding: { name: "3xn820", styles: "margin:0;transform:scaleX(-1);:dir(rtl){transform:scaleX(1);}" }
},
origin: {
left: { name: "26g2q5", styles: "" },
right: { name: "2i6k22", styles: "" }
}
},
compound: [
{
modifiers: { state: 'collapsed', origin: 'right' },
styles: { name: "3fcrtu", styles: "transform:scaleX(-1);" }
},
{
modifiers: { state: 'collapsing', origin: 'right' },
styles: { name: "4xtaa", styles: "transform:scaleX(-1);inset-inline-start:var(--cnvs-sys-space-x4);" }
},
{
modifiers: { state: 'expanded', origin: 'right' },
styles: { name: "rezto", styles: "transform:scaleX(1);inset-inline-start:var(--cnvs-sys-space-x4);" }
},
{
modifiers: { state: 'expanding', origin: 'right' },
styles: { name: "2tc6rs", styles: "transform:scaleX(1);inset-inline-start:var(--cnvs-sys-space-x4);" }
}
]
}, "side-panel-toggle-button-da8098");
/**
* A toggle button styled specifically for the side panel container.
*/
export const SidePanelToggleButton = createComponent('button')({
displayName: 'SidePanel.ToggleButton',
Component({ variant = undefined, icon = transformationImportIcon, tooltipTextExpand = 'Expand', tooltipTextCollapse = 'Collapse', ...elemProps }) {
const context = React.useContext(SidePanelContext);
return (_jsx(Tooltip, { title: context.state === 'collapsed' ? tooltipTextExpand : tooltipTextCollapse, type: "muted", children: _jsx(TertiaryButton, { type: "button", icon: icon, variant: variant, ...handleCsProp(elemProps, sidePanelToggleButtonStencil({
state: context.state,
origin: context.origin,
})), onClick: event => {
var _a;
//@ts-ignore this gets called from the useSidePanel hook.
(_a = elemProps.onClick) === null || _a === void 0 ? void 0 : _a.call(elemProps, event);
context.handleAnimationStart();
} }) }));
},
});