UNPKG

@sap-ux/ui-components

Version:
110 lines 4.34 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.UIToolbar = void 0; const React = __importStar(require("react")); const react_1 = require("@fluentui/react"); require("./UIToolbar.scss"); /** * UIToolbar component. * * @exports * @class {UIToolbar} * @extends {React.Component<UIToolbarProps, UIToolbarState>} */ class UIToolbar extends React.Component { /** * Initializes component properties. * * @param props */ constructor(props) { super(props); this.onResize = () => { const toolbarWidth = this.toolbarRef.current?.clientWidth; let breakPointLarge = 800; let breakPointMedium = 660; let breakPointSmall = 420; if (this.props.breakPointLarge) { breakPointLarge = this.props.breakPointLarge; } if (this.props.breakPointMedium) { breakPointMedium = this.props.breakPointMedium; } if (this.props.breakPointSmall) { breakPointSmall = this.props.breakPointSmall; } let toolbarWidthClassName = this.state.toolbarWidthClassName; let widthName = ''; if (toolbarWidth) { if (toolbarWidth > breakPointLarge) { toolbarWidthClassName = 'column-wide'; widthName = 'wide'; } if (toolbarWidth > breakPointMedium && toolbarWidth <= breakPointLarge) { toolbarWidthClassName = 'column-large'; widthName = 'large'; } if (toolbarWidth >= breakPointSmall && toolbarWidth <= breakPointMedium) { toolbarWidthClassName = 'column-medium'; widthName = 'medium'; } if (toolbarWidth < breakPointSmall) { toolbarWidthClassName = 'column-small'; widthName = 'small'; } this.setState({ toolbarWidthClassName: toolbarWidthClassName }); if (this.props.onResize) { this.props.onResize(toolbarWidth, widthName); } } }; this.state = { toolbarWidthClassName: 'column-large' }; this.toolbarRef = React.createRef(); this.resizeObserver = new ResizeObserver(this.onResize); } componentDidMount() { this.resizeObserver.observe(this.toolbarRef.current); this.onResize(); } /** * @returns {React.ReactNode} */ render() { const divProps = (0, react_1.getNativeProps)(this.props, react_1.divProperties, [ 'className', 'children' ]); return (React.createElement("div", { ...divProps, tabIndex: -1, ref: this.toolbarRef, className: `ui-toolbar ${this.state.toolbarWidthClassName} ${this.props.className ? this.props.className : ''}`, role: "toolbar" }, React.createElement("div", { className: "ui-toolbar__container" }, React.createElement("div", { className: "ui-toolbar__content" }, this.props.children)))); } } exports.UIToolbar = UIToolbar; //# sourceMappingURL=UIToolbar.js.map