@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.
70 lines (69 loc) • 3.55 kB
JavaScript
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.SidePanelToggleButton = void 0;
/** @jsxRuntime classic */
/** @jsx jsx */
const React = __importStar(require("react"));
const common_1 = require("@workday/canvas-kit-react/common");
const react_1 = require("@emotion/react");
const button_1 = require("@workday/canvas-kit-react/button");
const tokens_1 = require("@workday/canvas-kit-react/tokens");
const canvas_system_icons_web_1 = require("@workday/canvas-system-icons-web");
const tooltip_1 = require("@workday/canvas-kit-react/tooltip");
const hooks_1 = require("./hooks");
/**
* A toggle button styled specifically for the side panel container.
*/
exports.SidePanelToggleButton = (0, common_1.createComponent)('button')({
displayName: 'SidePanel.ToggleButton',
Component({ variant = undefined, icon = canvas_system_icons_web_1.transformationImportIcon, tooltipTextExpand = 'Expand', tooltipTextCollapse = 'Collapse', ...elemProps }) {
const context = React.useContext(hooks_1.SidePanelContext);
const useRTLOrigin = () => {
const isRTL = (0, common_1.useIsRTL)();
// if the direction is set to RTl, flip the origin
if (isRTL) {
return context.origin === 'left' ? 'right' : 'left';
}
// Otherwise, default to returning the origin
return context.origin;
};
const rtlOrigin = useRTLOrigin();
// Note: Depending on the collapsed width, the button could "jump" to it's final position.
const buttonStyle = (0, react_1.css)({
position: 'absolute',
top: tokens_1.space.m,
width: tokens_1.space.l,
right: context.state === 'collapsed' ? 0 : rtlOrigin === 'left' ? tokens_1.space.s : undefined,
left: context.state === 'collapsed' ? 0 : rtlOrigin === 'right' ? tokens_1.space.s : undefined,
margin: context.state === 'collapsed' ? 'auto' : 0,
transform: context.state === 'collapsed' || context.state === 'collapsing'
? `scaleX(${rtlOrigin === 'left' ? '1' : '-1'})`
: `scaleX(${rtlOrigin === 'left' ? '-1' : '1'})`,
});
return ((0, react_1.jsx)(tooltip_1.Tooltip, { title: context.state === 'collapsed' ? tooltipTextExpand : tooltipTextCollapse, type: "muted" },
(0, react_1.jsx)(button_1.TertiaryButton, { type: "button", css: buttonStyle, icon: icon, variant: variant, ...elemProps })));
},
});
;