@zendeskgarden/react-grid 8.75.1 → 8.76.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js DELETED
@@ -1,975 +0,0 @@
1
- /**
2
- * Copyright Zendesk, Inc.
3
- *
4
- * Use of this source code is governed under the Apache License, Version 2.0
5
- * found at http://www.apache.org/licenses/LICENSE-2.0.
6
- */
7
-
8
- import React, { createContext, useContext, useMemo, useState, useCallback, forwardRef, useRef, useEffect } from 'react';
9
- import PropTypes from 'prop-types';
10
- import styled, { css, ThemeContext } from 'styled-components';
11
- import { math, stripUnit } from 'polished';
12
- import { retrieveComponentStyles, DEFAULT_THEME, getColorV8, SELECTOR_FOCUS_VISIBLE, focusStyles, useDocument, useText } from '@zendeskgarden/react-theming';
13
- import { ChevronButton } from '@zendeskgarden/react-buttons';
14
- import { useId, composeEventHandlers } from '@zendeskgarden/container-utilities';
15
- import useResizeObserver from 'use-resize-observer';
16
- import mergeRefs from 'react-merge-refs';
17
- import { useSplitter } from '@zendeskgarden/container-splitter';
18
- import { Tooltip } from '@zendeskgarden/react-tooltips';
19
-
20
- function _extends() {
21
- _extends = Object.assign ? Object.assign.bind() : function (target) {
22
- for (var i = 1; i < arguments.length; i++) {
23
- var source = arguments[i];
24
- for (var key in source) {
25
- if (Object.prototype.hasOwnProperty.call(source, key)) {
26
- target[key] = source[key];
27
- }
28
- }
29
- }
30
- return target;
31
- };
32
- return _extends.apply(this, arguments);
33
- }
34
-
35
- const ALIGN_ITEMS = ['start', 'end', 'center', 'baseline', 'stretch'];
36
- const ALIGN_SELF = ['auto', ...ALIGN_ITEMS];
37
- const DIRECTION = ['row', 'row-reverse', 'column', 'column-reverse'];
38
- const JUSTIFY_CONTENT = ['start', 'end', 'center', 'between', 'around'];
39
- const TEXT_ALIGN = ['start', 'end', 'center', 'justify'];
40
- const SPACE = [false, 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
41
- const WRAP = ['nowrap', 'wrap', 'wrap-reverse'];
42
- const ORIENTATION = ['top', 'bottom', 'start', 'end'];
43
-
44
- const COMPONENT_ID$7 = 'grid.col';
45
- const colorStyles$4 = props => {
46
- const backgroundColor = getColorV8('primaryHue', 600, props.theme, 0.1);
47
- return css(["background-clip:content-box;background-color:", ";"], backgroundColor);
48
- };
49
- const flexStyles$1 = (size, alignSelf, textAlign, offset, order, props) => {
50
- const margin = offset && `${math(`${offset} / ${props.columns} * 100`)}%`;
51
- let flexBasis;
52
- let flexGrow;
53
- let maxWidth;
54
- let width;
55
- if (typeof size === 'boolean') {
56
- flexBasis = 0;
57
- flexGrow = 1;
58
- maxWidth = '100%';
59
- } else if (size === 'auto') {
60
- flexBasis = 'auto';
61
- flexGrow = 0;
62
- maxWidth = '100%';
63
- width = 'auto';
64
- } else if (size !== undefined) {
65
- flexBasis = `${math(`${size} / ${props.columns} * 100`)}%`;
66
- flexGrow = 0;
67
- maxWidth = flexBasis;
68
- }
69
- let horizontalAlign;
70
- if (textAlign === 'start') {
71
- horizontalAlign = props.theme.rtl ? 'right' : 'left';
72
- } else if (textAlign === 'end') {
73
- horizontalAlign = props.theme.rtl ? 'left' : 'right';
74
- } else {
75
- horizontalAlign = textAlign;
76
- }
77
- let flexOrder;
78
- if (order === 'first') {
79
- flexOrder = -1;
80
- } else if (order === 'last') {
81
- flexOrder = math(`${props.columns} + 1`);
82
- } else {
83
- flexOrder = order;
84
- }
85
- return css(["flex-basis:", ";flex-grow:", ";flex-shrink:", ";align-self:", ";order:", ";margin-", ":", ";width:", ";max-width:", ";text-align:", ";"], flexBasis, flexGrow, size && 0, alignSelf === 'start' || alignSelf === 'end' ? `flex-${alignSelf}` : alignSelf, flexOrder, props.theme.rtl ? 'right' : 'left', margin, width, maxWidth, horizontalAlign);
86
- };
87
- const mediaStyles$1 = (minWidth, size, alignSelf, textAlign, offset, order, props) => {
88
- return css(["@media (min-width:", "){", ";}"], minWidth, flexStyles$1(size, alignSelf, textAlign, offset, order, props));
89
- };
90
- const sizeStyles$5 = props => {
91
- const padding = props.gutters ? math(`${props.theme.space[props.gutters]} / 2`) : 0;
92
- return css(["padding-right:", ";padding-left:", ";"], padding, padding);
93
- };
94
- const StyledCol = styled.div.attrs({
95
- 'data-garden-id': COMPONENT_ID$7,
96
- 'data-garden-version': '8.75.1'
97
- }).withConfig({
98
- displayName: "StyledCol",
99
- componentId: "sc-inuw62-0"
100
- })(["box-sizing:border-box;width:100%;", ";", ";", ";", ";", ";", ";", ";", ";", ";"], props => flexStyles$1(!props.sizeAll && (props.xs || props.sm || props.md || props.lg || props.xl) ? undefined : props.sizeAll || false, props.alignSelf, props.textAlign, props.offset, props.order, props), props => sizeStyles$5(props), props => props.debug && colorStyles$4(props), props => mediaStyles$1(props.theme.breakpoints.xs, props.xs, props.alignSelfXs, props.textAlignXs, props.offsetXs, props.orderXs, props), props => mediaStyles$1(props.theme.breakpoints.sm, props.sm, props.alignSelfSm, props.textAlignSm, props.offsetSm, props.orderSm, props), props => mediaStyles$1(props.theme.breakpoints.md, props.md, props.alignSelfMd, props.textAlignMd, props.offsetMd, props.orderMd, props), props => mediaStyles$1(props.theme.breakpoints.lg, props.lg, props.alignSelfLg, props.textAlignLg, props.offsetLg, props.orderLg, props), props => mediaStyles$1(props.theme.breakpoints.xl, props.xl, props.alignSelfXl, props.textAlignXl, props.offsetXl, props.orderXl, props), props => retrieveComponentStyles(COMPONENT_ID$7, props));
101
- StyledCol.defaultProps = {
102
- columns: 12,
103
- theme: DEFAULT_THEME
104
- };
105
-
106
- const COMPONENT_ID$6 = 'grid.grid';
107
- const colorStyles$3 = props => {
108
- const borderColor = getColorV8(props.theme.palette.crimson, 400, props.theme, 0.5);
109
- const borderWidth = math(`${props.theme.borderWidths.sm} * 2`);
110
- return css(["box-shadow:-", " 0 0 0 ", ",", " 0 0 0 ", ";"], borderWidth, borderColor, borderWidth, borderColor);
111
- };
112
- const sizeStyles$4 = props => {
113
- const padding = props.gutters ? math(`${props.theme.space[props.gutters]} / 2`) : 0;
114
- return css(["padding-right:", ";padding-left:", ";"], padding, padding);
115
- };
116
- const StyledGrid = styled.div.attrs({
117
- 'data-garden-id': COMPONENT_ID$6,
118
- 'data-garden-version': '8.75.1'
119
- }).withConfig({
120
- displayName: "StyledGrid",
121
- componentId: "sc-oxgg5i-0"
122
- })(["direction:", ";margin-right:auto;margin-left:auto;width:100%;box-sizing:border-box;", ";", ";", ";"], props => props.theme.rtl && 'rtl', props => sizeStyles$4(props), props => props.debug && colorStyles$3(props), props => retrieveComponentStyles(COMPONENT_ID$6, props));
123
- StyledGrid.defaultProps = {
124
- gutters: 'md',
125
- theme: DEFAULT_THEME
126
- };
127
-
128
- const COMPONENT_ID$5 = 'grid.row';
129
- const colorStyles$2 = props => {
130
- const borderColor = getColorV8(props.theme.palette.mint, 600, props.theme, 0.5);
131
- const borderWidth = props.theme.borderWidths.sm;
132
- return css(["box-shadow:inset 0 ", " 0 0 ", ",inset 0 -", " 0 0 ", ";"], borderWidth, borderColor, borderWidth, borderColor);
133
- };
134
- const flexStyles = (alignItems, justifyContent, wrap) => {
135
- let flexAlignItems;
136
- let flexJustifyContent;
137
- if (alignItems === 'start' || alignItems === 'end') {
138
- flexAlignItems = `flex-${alignItems}`;
139
- } else {
140
- flexAlignItems = alignItems;
141
- }
142
- if (justifyContent === 'start' || justifyContent === 'end') {
143
- flexJustifyContent = `flex-${justifyContent}`;
144
- } else if (justifyContent === 'between' || justifyContent === 'around') {
145
- flexJustifyContent = `space-${justifyContent}`;
146
- } else {
147
- flexJustifyContent = justifyContent;
148
- }
149
- return css(["flex-wrap:", ";align-items:", ";justify-content:", ";"], wrap, flexAlignItems, flexJustifyContent);
150
- };
151
- const mediaStyles = (minWidth, alignItems, justifyContent, wrap) => {
152
- return css(["@media (min-width:", "){", ";}"], minWidth, flexStyles(alignItems, justifyContent, wrap));
153
- };
154
- const sizeStyles$3 = props => {
155
- const margin = props.gutters ? math(`${props.theme.space[props.gutters]} / 2`) : 0;
156
- return css(["margin-right:-", ";margin-left:-", ";"], margin, margin);
157
- };
158
- const StyledRow = styled.div.attrs({
159
- 'data-garden-id': COMPONENT_ID$5,
160
- 'data-garden-version': '8.75.1'
161
- }).withConfig({
162
- displayName: "StyledRow",
163
- componentId: "sc-xjsdg1-0"
164
- })(["display:flex;box-sizing:border-box;", " ", ";", ";", ";", ";", ";", ";", ";", ";"], props => flexStyles(props.alignItems, props.justifyContent, props.wrapAll), props => sizeStyles$3(props), props => props.debug && colorStyles$2(props), props => mediaStyles(props.theme.breakpoints.xs, props.alignItemsXs, props.justifyContentXs, props.wrapXs), props => mediaStyles(props.theme.breakpoints.sm, props.alignItemsSm, props.justifyContentSm, props.wrapSm), props => mediaStyles(props.theme.breakpoints.md, props.alignItemsMd, props.justifyContentMd, props.wrapMd), props => mediaStyles(props.theme.breakpoints.lg, props.alignItemsLg, props.justifyContentLg, props.wrapLg), props => mediaStyles(props.theme.breakpoints.xl, props.alignItemsXl, props.justifyContentXl, props.wrapXl), props => retrieveComponentStyles(COMPONENT_ID$5, props));
165
- StyledRow.defaultProps = {
166
- wrapAll: 'wrap',
167
- theme: DEFAULT_THEME
168
- };
169
-
170
- const COMPONENT_ID$4 = 'pane';
171
- const StyledPane = styled.div.attrs({
172
- 'data-garden-id': COMPONENT_ID$4,
173
- 'data-garden-version': '8.75.1'
174
- }).withConfig({
175
- displayName: "StyledPane",
176
- componentId: "sc-1ltjst7-0"
177
- })(["position:relative;min-width:0;min-height:0;", ";"], props => retrieveComponentStyles(COMPONENT_ID$4, props));
178
- StyledPane.defaultProps = {
179
- theme: DEFAULT_THEME
180
- };
181
-
182
- const COMPONENT_ID$3 = 'pane.content';
183
- const StyledPaneContent = styled.div.attrs({
184
- 'data-garden-id': COMPONENT_ID$3,
185
- 'data-garden-version': '8.75.1'
186
- }).withConfig({
187
- displayName: "StyledPaneContent",
188
- componentId: "sc-1b38mbh-0"
189
- })(["height:100%;overflow:auto;&[hidden]{display:none;}", ";"], props => retrieveComponentStyles(COMPONENT_ID$3, props));
190
- StyledPaneContent.defaultProps = {
191
- theme: DEFAULT_THEME
192
- };
193
-
194
- const COMPONENT_ID$2 = 'pane.splitter';
195
- const colorStyles$1 = props => {
196
- const color = getColorV8('neutralHue', 300, props.theme);
197
- const hoverColor = getColorV8('primaryHue', 600, props.theme);
198
- const activeColor = getColorV8('primaryHue', 800, props.theme);
199
- return css(["&::before{background-color:", ";}&:hover::before{background-color:", ";}", " &:active::before{background-color:", ";}"], color, hoverColor, focusStyles({
200
- theme: props.theme,
201
- hue: hoverColor,
202
- styles: {
203
- backgroundColor: hoverColor
204
- },
205
- selector: '&:focus-visible::before, &[data-garden-focus-visible="true"]::before'
206
- }), activeColor);
207
- };
208
- const sizeStyles$2 = props => {
209
- const size = math(`${props.theme.shadowWidths.md} * 2`);
210
- const separatorSize = math(`${props.theme.borderWidths.sm} * 2`);
211
- const offset = math(`-${size} / 2`);
212
- let cursor;
213
- let top;
214
- let right;
215
- let left;
216
- let bottom;
217
- let width;
218
- let height;
219
- let separatorWidth;
220
- let separatorHeight;
221
- switch (props.orientation) {
222
- case 'top':
223
- cursor = 'row-resize';
224
- top = offset;
225
- width = '100%';
226
- height = size;
227
- separatorWidth = width;
228
- separatorHeight = props.theme.borderWidths.sm;
229
- break;
230
- case 'bottom':
231
- cursor = 'row-resize';
232
- bottom = offset;
233
- width = '100%';
234
- height = size;
235
- separatorWidth = width;
236
- separatorHeight = props.theme.borderWidths.sm;
237
- break;
238
- case 'start':
239
- cursor = 'col-resize';
240
- top = 0;
241
- width = size;
242
- height = '100%';
243
- separatorWidth = props.theme.borderWidths.sm;
244
- separatorHeight = height;
245
- if (props.theme.rtl) {
246
- right = offset;
247
- } else {
248
- left = offset;
249
- }
250
- break;
251
- case 'end':
252
- default:
253
- cursor = 'col-resize';
254
- top = 0;
255
- width = size;
256
- height = '100%';
257
- separatorWidth = props.theme.borderWidths.sm;
258
- separatorHeight = height;
259
- if (props.theme.rtl) {
260
- left = offset;
261
- } else {
262
- right = offset;
263
- }
264
- break;
265
- }
266
- const dimensionProperty = width === '100%' ? 'height' : 'width';
267
- return css(["top:", ";right:", ";bottom:", ";left:", ";cursor:", ";width:", ";height:", ";&::before{width:", ";height:", ";}&:hover::before{", ":", ";}&:focus::before,&:focus-visible::before,&[data-garden-focus-visible]::before{", ":", ";}&:focus-visible::before,&[data-garden-focus-visible]::before{border-radius:", ";}"], top, right, bottom, left, props.isFixed ? 'pointer' : cursor, width, height, separatorWidth, separatorHeight, dimensionProperty, separatorSize, dimensionProperty, separatorSize, props.theme.borderRadii.md);
268
- };
269
- const StyledPaneSplitter = styled.div.attrs({
270
- 'data-garden-id': COMPONENT_ID$2,
271
- 'data-garden-version': '8.75.1'
272
- }).withConfig({
273
- displayName: "StyledPaneSplitter",
274
- componentId: "sc-jylemn-0"
275
- })(["display:flex;position:absolute;align-items:center;justify-content:center;z-index:1;user-select:none;", ";", "{z-index:2;}&::before{position:absolute;transition:box-shadow 0.1s ease-in-out,background-color 0.25s ease-in-out;z-index:-1;content:'';}", ";", ";"], sizeStyles$2, SELECTOR_FOCUS_VISIBLE, colorStyles$1, props => retrieveComponentStyles(COMPONENT_ID$2, props));
276
- StyledPaneSplitter.defaultProps = {
277
- theme: DEFAULT_THEME
278
- };
279
-
280
- const COMPONENT_ID$1 = 'pane.splitter_button';
281
- const getSize = theme => theme.space.base * 6;
282
- const sizeStyles$1 = _ref => {
283
- let {
284
- theme
285
- } = _ref;
286
- const size = `${getSize(theme)}px`;
287
- return css(["width:", ";min-width:", ";height:", ";"], size, size, size);
288
- };
289
- const transformStyles = props => {
290
- let degrees = 0;
291
- if (props.isRotated) {
292
- degrees = props.theme.rtl ? -180 : 180;
293
- }
294
- if (props.orientation === 'end') {
295
- degrees += props.theme.rtl ? -90 : 90;
296
- } else if (props.orientation === 'start') {
297
- degrees += props.theme.rtl ? 90 : -90;
298
- } else if (props.orientation === 'bottom') {
299
- degrees += 180;
300
- }
301
- return css(["& > svg{transform:rotate(", "deg);}"], degrees);
302
- };
303
- const StyledPaneSplitterButton = styled(ChevronButton).attrs({
304
- 'data-garden-id': COMPONENT_ID$1,
305
- 'data-garden-version': '8.75.1',
306
- isBasic: true,
307
- isPill: true,
308
- size: 'small'
309
- }).withConfig({
310
- displayName: "StyledPaneSplitterButton",
311
- componentId: "sc-zh032e-0"
312
- })(["", ";", ";", ";"], sizeStyles$1, transformStyles, props => retrieveComponentStyles(COMPONENT_ID$1, props));
313
- StyledPaneSplitterButton.defaultProps = {
314
- theme: DEFAULT_THEME
315
- };
316
-
317
- const COMPONENT_ID = 'pane.splitter_button_container';
318
- const colorStyles = _ref => {
319
- let {
320
- theme
321
- } = _ref;
322
- const backgroundColor = getColorV8('background', 600 , theme);
323
- const boxShadow = theme.shadows.lg(`${theme.space.base}px`, `${theme.space.base * 2}px`, getColorV8('chromeHue', 600, theme, 0.15));
324
- return css(["box-shadow:", ";background-color:", ";"], boxShadow, backgroundColor);
325
- };
326
- const positionStyles = props => {
327
- let top;
328
- let left;
329
- let right;
330
- let bottom;
331
- const size = getSize(props.theme);
332
- const inset = `-${size / 2}px`;
333
- if (props.placement === 'center' || props.splitterSize < size * 3) {
334
- const center = `${props.splitterSize / 2 - size / 2}px`;
335
- switch (`${props.orientation}-${props.theme.rtl ? 'rtl' : 'ltr'}`) {
336
- case 'top-ltr':
337
- case 'top-rtl':
338
- top = inset;
339
- left = center;
340
- break;
341
- case 'start-ltr':
342
- case 'end-rtl':
343
- top = center;
344
- left = inset;
345
- break;
346
- case 'end-ltr':
347
- case 'start-rtl':
348
- top = center;
349
- right = inset;
350
- break;
351
- case 'bottom-ltr':
352
- case 'bottom-rtl':
353
- bottom = inset;
354
- right = center;
355
- break;
356
- }
357
- } else {
358
- const offset = `${size}px`;
359
- switch (`${props.orientation}-${props.placement}-${props.theme.rtl ? 'rtl' : 'ltr'}`) {
360
- case 'top-end-ltr':
361
- case 'top-end-rtl':
362
- case 'top-start-rtl':
363
- top = inset;
364
- right = offset;
365
- break;
366
- case 'bottom-end-ltr':
367
- case 'bottom-end-rtl':
368
- case 'bottom-start-rtl':
369
- bottom = inset;
370
- right = offset;
371
- break;
372
- case 'start-start-ltr':
373
- case 'end-start-rtl':
374
- top = offset;
375
- left = inset;
376
- break;
377
- case 'start-end-ltr':
378
- case 'end-end-rtl':
379
- bottom = offset;
380
- left = inset;
381
- break;
382
- case 'end-start-ltr':
383
- case 'start-start-rtl':
384
- top = offset;
385
- right = inset;
386
- break;
387
- case 'end-end-ltr':
388
- case 'start-end-rtl':
389
- bottom = offset;
390
- right = inset;
391
- break;
392
- case 'top-start-ltr':
393
- top = inset;
394
- left = offset;
395
- break;
396
- case 'bottom-start-ltr':
397
- bottom = inset;
398
- left = offset;
399
- break;
400
- }
401
- }
402
- return css(["top:", ";right:", ";bottom:", ";left:", ";"], top, right, bottom, left);
403
- };
404
- const sizeStyles = _ref2 => {
405
- let {
406
- theme
407
- } = _ref2;
408
- const size = getSize(theme);
409
- return css(["border-radius:", "px;width:", "px;height:", "px;"], size, size, size);
410
- };
411
- const minimumSplitterSize = theme => stripUnit(math(`${theme.shadowWidths.md} * 2 + ${getSize(theme)}`));
412
- const StyledPaneSplitterButtonContainer = styled.div.withConfig({
413
- displayName: "StyledPaneSplitterButtonContainer",
414
- componentId: "sc-1w84y62-0"
415
- })(["display:", ";position:absolute;transition:box-shadow 0.1s ease-in-out,opacity 0.25s ease-in-out 0.1s;opacity:0;z-index:2;", ";", ";", ";&:hover,&:focus-within,", ":hover ~ &,", ":focus-visible ~ &{opacity:1;}", ";"], props => props.splitterSize <= minimumSplitterSize(props.theme) ? 'none' : undefined, positionStyles, sizeStyles, colorStyles, StyledPaneSplitter, StyledPaneSplitter, props => retrieveComponentStyles(COMPONENT_ID, props));
416
- StyledPaneSplitterButtonContainer.defaultProps = {
417
- theme: DEFAULT_THEME
418
- };
419
-
420
- const GridContext = createContext({
421
- gutters: 'md'
422
- });
423
- const useGridContext = () => {
424
- return useContext(GridContext);
425
- };
426
-
427
- const Col = React.forwardRef((_ref, ref) => {
428
- let {
429
- size,
430
- ...props
431
- } = _ref;
432
- const {
433
- columns,
434
- gutters,
435
- debug
436
- } = useGridContext();
437
- return React.createElement(StyledCol, _extends({
438
- sizeAll: size,
439
- columns: columns,
440
- gutters: gutters,
441
- debug: debug,
442
- ref: ref
443
- }, props));
444
- });
445
- Col.displayName = 'Col';
446
- Col.propTypes = {
447
- size: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
448
- xs: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.bool]),
449
- sm: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.bool]),
450
- md: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.bool]),
451
- lg: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.bool]),
452
- xl: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.bool]),
453
- alignSelf: PropTypes.oneOf(ALIGN_SELF),
454
- alignSelfXs: PropTypes.oneOf(ALIGN_SELF),
455
- alignSelfSm: PropTypes.oneOf(ALIGN_SELF),
456
- alignSelfMd: PropTypes.oneOf(ALIGN_SELF),
457
- alignSelfLg: PropTypes.oneOf(ALIGN_SELF),
458
- alignSelfXl: PropTypes.oneOf(ALIGN_SELF),
459
- textAlign: PropTypes.oneOf(TEXT_ALIGN),
460
- textAlignXs: PropTypes.oneOf(TEXT_ALIGN),
461
- textAlignSm: PropTypes.oneOf(TEXT_ALIGN),
462
- textAlignMd: PropTypes.oneOf(TEXT_ALIGN),
463
- textAlignLg: PropTypes.oneOf(TEXT_ALIGN),
464
- textAlignXl: PropTypes.oneOf(TEXT_ALIGN),
465
- offset: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
466
- offsetXs: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
467
- offsetSm: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
468
- offsetMd: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
469
- offsetLg: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
470
- offsetXl: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
471
- order: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
472
- orderXs: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
473
- orderSm: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
474
- orderMd: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
475
- orderLg: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
476
- orderXl: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
477
- };
478
-
479
- const Grid = React.forwardRef((_ref, ref) => {
480
- let {
481
- columns,
482
- debug,
483
- ...props
484
- } = _ref;
485
- const value = useMemo(() => ({
486
- columns,
487
- gutters: props.gutters,
488
- debug
489
- }), [columns, props.gutters, debug]);
490
- return React.createElement(GridContext.Provider, {
491
- value: value
492
- }, React.createElement(StyledGrid, _extends({
493
- debug: debug,
494
- ref: ref
495
- }, props)));
496
- });
497
- Grid.displayName = 'Grid';
498
- Grid.propTypes = {
499
- columns: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
500
- gutters: PropTypes.oneOf(SPACE),
501
- debug: PropTypes.bool
502
- };
503
- Grid.defaultProps = {
504
- columns: 12,
505
- gutters: 'md'
506
- };
507
-
508
- const Row = React.forwardRef((_ref, ref) => {
509
- let {
510
- wrap,
511
- ...props
512
- } = _ref;
513
- const {
514
- gutters,
515
- debug
516
- } = useGridContext();
517
- return React.createElement(StyledRow, _extends({
518
- gutters: gutters,
519
- debug: debug,
520
- wrapAll: wrap,
521
- ref: ref
522
- }, props));
523
- });
524
- Row.displayName = 'Row';
525
- Row.propTypes = {
526
- alignItems: PropTypes.oneOf(ALIGN_ITEMS),
527
- alignItemsXs: PropTypes.oneOf(ALIGN_ITEMS),
528
- alignItemsSm: PropTypes.oneOf(ALIGN_ITEMS),
529
- alignItemsMd: PropTypes.oneOf(ALIGN_ITEMS),
530
- alignItemsLg: PropTypes.oneOf(ALIGN_ITEMS),
531
- alignItemsXl: PropTypes.oneOf(ALIGN_ITEMS),
532
- justifyContent: PropTypes.oneOf(JUSTIFY_CONTENT),
533
- justifyContentXs: PropTypes.oneOf(JUSTIFY_CONTENT),
534
- justifyContentSm: PropTypes.oneOf(JUSTIFY_CONTENT),
535
- justifyContentMd: PropTypes.oneOf(JUSTIFY_CONTENT),
536
- justifyContentLg: PropTypes.oneOf(JUSTIFY_CONTENT),
537
- justifyContentXl: PropTypes.oneOf(JUSTIFY_CONTENT),
538
- wrap: PropTypes.oneOf(WRAP),
539
- wrapXs: PropTypes.oneOf(WRAP),
540
- wrapSm: PropTypes.oneOf(WRAP),
541
- wrapMd: PropTypes.oneOf(WRAP),
542
- wrapLg: PropTypes.oneOf(WRAP),
543
- wrapXl: PropTypes.oneOf(WRAP)
544
- };
545
-
546
- const PaneProviderContext = createContext({});
547
- const usePaneProviderContextData = providerId => {
548
- const context = useContext(PaneProviderContext);
549
- const id = providerId || context.providerId;
550
- return id && context.contextData ? context.contextData[id] : undefined;
551
- };
552
- const usePaneProviderContext = () => useContext(PaneProviderContext);
553
-
554
- const getPixelsPerFr = (totalFrs, totalDimension) => {
555
- return totalDimension / totalFrs;
556
- };
557
- const convertToPixels = (values, pixelsPerFr) => {
558
- return Object.entries(values).reduce((prev, _ref) => {
559
- let [key, value] = _ref;
560
- prev[key] = value * pixelsPerFr;
561
- return prev;
562
- }, {});
563
- };
564
- const PaneProvider = _ref2 => {
565
- let {
566
- id,
567
- totalPanesWidth,
568
- totalPanesHeight,
569
- defaultRowValues,
570
- defaultColumnValues,
571
- rowValues,
572
- columnValues,
573
- onChange,
574
- children
575
- } = _ref2;
576
- const isControlled = rowValues !== undefined && rowValues !== null && columnValues !== undefined && columnValues !== null;
577
- const [rowState, setRowState] = useState(defaultRowValues || {});
578
- const [columnState, setColumnState] = useState(defaultColumnValues || {});
579
- const rowsTrack = isControlled ? rowValues : rowState;
580
- const columnsTrack = isControlled ? columnValues : columnState;
581
- const setRowsTrack = useCallback(values => {
582
- if (isControlled && onChange) {
583
- return onChange(values(rowsTrack), columnsTrack);
584
- }
585
- return setRowState(values);
586
- }, [isControlled, onChange, setRowState, columnsTrack, rowsTrack]);
587
- const setColumnsTrack = useCallback(values => {
588
- if (isControlled && onChange) {
589
- return onChange(rowsTrack, values(columnsTrack));
590
- }
591
- return setColumnState(values);
592
- }, [isControlled, onChange, setColumnState, rowsTrack, columnsTrack]);
593
- const totalFractions = useMemo(() => ({
594
- rows: Object.values(rowsTrack).reduce((prev, value) => value + prev, 0),
595
- columns: Object.values(columnsTrack).reduce((prev, value) => value + prev, 0)
596
- }), [rowsTrack, columnsTrack]);
597
- const pixelsPerFr = useMemo(() => ({
598
- rows: getPixelsPerFr(totalFractions.rows, totalPanesHeight),
599
- columns: getPixelsPerFr(totalFractions.columns, totalPanesWidth)
600
- }), [totalFractions, totalPanesHeight, totalPanesWidth]);
601
- const layoutStateInPixels = useMemo(() => ({
602
- rows: convertToPixels(rowsTrack, pixelsPerFr.rows),
603
- columns: convertToPixels(columnsTrack, pixelsPerFr.columns)
604
- }), [rowsTrack, columnsTrack, pixelsPerFr]);
605
- const layoutIndices = useMemo(() => {
606
- const rowArray = Object.keys(rowsTrack);
607
- const columnArray = Object.keys(columnsTrack);
608
- const rows = rowArray.reduce((prev, key, index) => {
609
- prev[key] = index;
610
- return prev;
611
- }, {});
612
- const columns = columnArray.reduce((prev, key, index) => {
613
- prev[key] = index;
614
- return prev;
615
- }, {});
616
- return {
617
- rows,
618
- columns,
619
- rowArray,
620
- columnArray
621
- };
622
- }, [rowsTrack, columnsTrack]);
623
- const setRowValue = useCallback((isTop, splitterId, value) => {
624
- const {
625
- rows,
626
- rowArray
627
- } = layoutIndices;
628
- const stealFromTraversal = isTop ? -1 : 1;
629
- const addToTraversal = 0;
630
- setRowsTrack(state => {
631
- const oldValue = rowsTrack[splitterId];
632
- const stealFromIndex = rows[splitterId] + stealFromTraversal;
633
- const addToIndex = rows[splitterId] + addToTraversal;
634
- const stealFromKey = rowArray[stealFromIndex];
635
- const addToKey = rowArray[addToIndex];
636
- const difference = oldValue - value;
637
- const nextState = {
638
- ...state
639
- };
640
- nextState[addToKey] = rowsTrack[addToKey] - difference;
641
- nextState[stealFromKey] = rowsTrack[stealFromKey] + difference;
642
- return nextState;
643
- });
644
- }, [layoutIndices, rowsTrack, setRowsTrack]);
645
- const setColumnValue = useCallback((isStart, splitterId, value) => {
646
- const {
647
- columns,
648
- columnArray
649
- } = layoutIndices;
650
- const stealFromTraversal = isStart ? -1 : 1;
651
- const addToTraversal = 0;
652
- setColumnsTrack(state => {
653
- const stealFromIndex = columns[splitterId] + stealFromTraversal;
654
- const addToIndex = columns[splitterId] + addToTraversal;
655
- const oldValue = columnsTrack[splitterId];
656
- const stealFromKey = columnArray[stealFromIndex];
657
- const addToKey = columnArray[addToIndex];
658
- const difference = oldValue - value;
659
- const nextState = {
660
- ...state
661
- };
662
- nextState[addToKey] = columnsTrack[addToKey] - difference;
663
- nextState[stealFromKey] = columnsTrack[stealFromKey] + difference;
664
- return nextState;
665
- });
666
- }, [layoutIndices, columnsTrack, setColumnsTrack]);
667
- const getColumnValue = useCallback((splitterKey, isPixels) => {
668
- if (isPixels) {
669
- return layoutStateInPixels.columns[splitterKey];
670
- }
671
- return columnsTrack[splitterKey];
672
- }, [columnsTrack, layoutStateInPixels]);
673
- const getRowValue = useCallback((splitterKey, isPixels) => {
674
- if (isPixels) {
675
- return layoutStateInPixels.rows[splitterKey];
676
- }
677
- return rowsTrack[splitterKey];
678
- }, [rowsTrack, layoutStateInPixels]);
679
- const getGridTemplateColumns = useCallback(isPixels => {
680
- const {
681
- columnArray
682
- } = layoutIndices;
683
- if (isPixels) {
684
- return columnArray.map(col => `${layoutStateInPixels.columns[col]}px`).join(' ');
685
- }
686
- return columnArray.map(col => `${columnsTrack[col]}fr`).join(' ');
687
- }, [layoutIndices, columnsTrack, layoutStateInPixels]);
688
- const getGridTemplateRows = useCallback(isPixels => {
689
- const {
690
- rowArray
691
- } = layoutIndices;
692
- if (isPixels) {
693
- return rowArray.map(row => `${layoutStateInPixels.rows[row]}px`).join(' ');
694
- }
695
- return rowArray.map(row => `${rowsTrack[row]}fr`).join(' ');
696
- }, [layoutIndices, rowsTrack, layoutStateInPixels]);
697
- const providerId = useId(id);
698
- const parentPaneProviderContext = usePaneProviderContext();
699
- const paneProviderContext = useMemo(() => providerId ? {
700
- providerId,
701
- contextData: {
702
- ...parentPaneProviderContext.contextData,
703
- [providerId]: {
704
- columnState,
705
- rowState,
706
- setRowValue,
707
- setColumnValue,
708
- getRowValue,
709
- getColumnValue,
710
- totalPanesHeight,
711
- totalPanesWidth,
712
- pixelsPerFr
713
- }
714
- }
715
- } : {}, [providerId, parentPaneProviderContext, rowState, columnState, setRowValue, setColumnValue, getRowValue, getColumnValue, totalPanesHeight, totalPanesWidth, pixelsPerFr]);
716
- return React.createElement(PaneProviderContext.Provider, {
717
- value: paneProviderContext
718
- }, children?.({
719
- id: providerId,
720
- getRowValue,
721
- getColumnValue,
722
- getGridTemplateColumns,
723
- getGridTemplateRows
724
- }));
725
- };
726
- PaneProvider.displayName = 'PaneProvider';
727
- PaneProvider.propTypes = {
728
- id: PropTypes.string,
729
- totalPanesWidth: PropTypes.number.isRequired,
730
- totalPanesHeight: PropTypes.number.isRequired,
731
- defaultRowValues: PropTypes.object,
732
- defaultColumnValues: PropTypes.object,
733
- rowValues: PropTypes.object,
734
- columnValues: PropTypes.object,
735
- onChange: PropTypes.func,
736
- children: PropTypes.func
737
- };
738
-
739
- const PaneContext = createContext({
740
- setId: () => undefined
741
- });
742
- const usePaneContext = () => {
743
- return useContext(PaneContext);
744
- };
745
-
746
- const PaneSplitterContext = createContext({
747
- orientation: 'start',
748
- min: 0,
749
- max: 0,
750
- layoutKey: '',
751
- valueNow: 0,
752
- size: 0,
753
- isRow: false
754
- });
755
- const usePaneSplitterContext = () => {
756
- return useContext(PaneSplitterContext);
757
- };
758
-
759
- const paneToSplitterOrientation = {
760
- start: 'vertical',
761
- end: 'vertical',
762
- top: 'horizontal',
763
- bottom: 'horizontal'
764
- };
765
- const orientationToDimension = {
766
- start: 'columns',
767
- end: 'columns',
768
- top: 'rows',
769
- bottom: 'rows'
770
- };
771
- const SplitterComponent = forwardRef((_ref, ref) => {
772
- let {
773
- children,
774
- providerId,
775
- layoutKey,
776
- min,
777
- max,
778
- orientation,
779
- isFixed,
780
- onMouseDown,
781
- onTouchStart,
782
- onKeyDown,
783
- onClick,
784
- ...props
785
- } = _ref;
786
- const paneProviderContext = usePaneProviderContextData(providerId);
787
- const paneContext = usePaneContext();
788
- const themeContext = useContext(ThemeContext);
789
- const environment = useDocument(themeContext);
790
- const isRow = orientationToDimension[orientation] === 'rows';
791
- const separatorRef = useRef(null);
792
- const splitterOrientation = paneToSplitterOrientation[orientation || 'end'];
793
- const pixelsPerFr = paneProviderContext ? paneProviderContext.pixelsPerFr[orientationToDimension[orientation]] : 0;
794
- const value = isRow ? paneProviderContext?.getRowValue(layoutKey, true) : paneProviderContext?.getColumnValue(layoutKey, true);
795
- const valueInFr = isRow ? paneProviderContext?.getRowValue(layoutKey) : paneProviderContext?.getColumnValue(layoutKey);
796
- const {
797
- getSeparatorProps,
798
- getPrimaryPaneProps
799
- } = useSplitter({
800
- orientation: splitterOrientation,
801
- isLeading: orientation === 'start' || orientation === 'top',
802
- min: min * pixelsPerFr,
803
- max: max * pixelsPerFr,
804
- rtl: themeContext.rtl,
805
- isFixed,
806
- environment,
807
- onChange: valueNow => {
808
- if (isRow) {
809
- return paneProviderContext?.setRowValue(orientation === 'top', layoutKey, valueNow / pixelsPerFr);
810
- }
811
- return paneProviderContext?.setColumnValue(orientation === 'start', layoutKey, valueNow / pixelsPerFr);
812
- },
813
- valueNow: value,
814
- separatorRef
815
- });
816
- useEffect(() => {
817
- if (!paneContext.id) {
818
- paneContext.setId(getPrimaryPaneProps().id);
819
- }
820
- }, [paneContext, getPrimaryPaneProps]);
821
- const ariaLabel = useText(SplitterComponent, props, 'aria-label', `${splitterOrientation} splitter`);
822
- const separatorProps = getSeparatorProps({
823
- 'aria-controls': paneContext.id,
824
- 'aria-label': ariaLabel,
825
- onMouseDown,
826
- onTouchStart,
827
- onKeyDown,
828
- onClick
829
- });
830
- const size = isRow ? separatorRef.current?.clientWidth : separatorRef.current?.clientHeight;
831
- return React.createElement(PaneSplitterContext.Provider, {
832
- value: useMemo(() => ({
833
- orientation,
834
- layoutKey,
835
- min,
836
- max,
837
- valueNow: valueInFr,
838
- size,
839
- isRow
840
- }), [orientation, layoutKey, min, max, valueInFr, size, isRow])
841
- }, React.createElement(StyledPaneSplitter, _extends({
842
- isFixed: isFixed,
843
- orientation: orientation
844
- }, separatorProps, props, {
845
- ref: mergeRefs([separatorRef, ref])
846
- })), children );
847
- });
848
- SplitterComponent.displayName = 'Pane.Splitter';
849
- SplitterComponent.propTypes = {
850
- layoutKey: PropTypes.string.isRequired,
851
- min: PropTypes.number.isRequired,
852
- max: PropTypes.number.isRequired,
853
- orientation: PropTypes.oneOf(ORIENTATION),
854
- isFixed: PropTypes.bool
855
- };
856
- SplitterComponent.defaultProps = {
857
- orientation: 'end'
858
- };
859
- const Splitter = SplitterComponent;
860
-
861
- const ContentComponent = forwardRef((props, ref) => {
862
- const {
863
- isVisible
864
- } = usePaneContext();
865
- return React.createElement(StyledPaneContent, _extends({
866
- hidden: !isVisible,
867
- ref: ref
868
- }, props));
869
- });
870
- ContentComponent.displayName = 'Pane.Content';
871
- const Content = ContentComponent;
872
-
873
- const SplitterButtonComponent = forwardRef((props, ref) => {
874
- const {
875
- label,
876
- placement: defaultPlacement
877
- } = props;
878
- const {
879
- orientation,
880
- layoutKey,
881
- min,
882
- max,
883
- isRow,
884
- valueNow,
885
- size,
886
- providerId
887
- } = usePaneSplitterContext();
888
- const paneProviderContext = usePaneProviderContextData(providerId);
889
- const isTop = orientation === 'top';
890
- const isStart = orientation === 'start';
891
- const isMin = valueNow === min;
892
- let placement = defaultPlacement;
893
- if (!defaultPlacement) {
894
- if (isRow) {
895
- placement = 'center';
896
- } else {
897
- placement = 'start';
898
- }
899
- }
900
- const setValue = useCallback(value => {
901
- if (isRow) {
902
- paneProviderContext.setRowValue(isTop, layoutKey, value);
903
- } else {
904
- paneProviderContext.setColumnValue(isStart, layoutKey, value);
905
- }
906
- }, [isRow, isTop, isStart, layoutKey, paneProviderContext]);
907
- const onClick = composeEventHandlers(props.onClick, () => {
908
- if (isMin) {
909
- setValue(max);
910
- } else {
911
- setValue(min);
912
- }
913
- });
914
- const onKeyDown = composeEventHandlers(props.onKeyDown, event => event.stopPropagation()
915
- );
916
- const onMouseDown = composeEventHandlers(props.onMouseDown, event => event.stopPropagation()
917
- );
918
- return React.createElement(StyledPaneSplitterButtonContainer, {
919
- orientation: orientation,
920
- placement: placement,
921
- splitterSize: size || 0
922
- }, React.createElement(Tooltip, {
923
- content: label,
924
- zIndex: 2,
925
- style: {
926
- cursor: 'default'
927
- },
928
- onMouseDown: e => e.stopPropagation()
929
- }, React.createElement(StyledPaneSplitterButton, _extends({
930
- "aria-label": label
931
- }, props, {
932
- orientation: orientation,
933
- isRotated: isMin,
934
- ref: ref,
935
- onClick: onClick,
936
- onKeyDown: onKeyDown,
937
- onMouseDown: onMouseDown
938
- }))));
939
- });
940
- SplitterButtonComponent.displayName = 'Pane.SplitterButton';
941
- const SplitterButton = SplitterButtonComponent;
942
-
943
- const PaneComponent = forwardRef((_ref, ref) => {
944
- let {
945
- children,
946
- ...props
947
- } = _ref;
948
- const [paneId, setPaneId] = useState();
949
- const observerRef = useRef(null);
950
- const {
951
- width = 0,
952
- height = 0
953
- } = useResizeObserver({
954
- ref: observerRef
955
- });
956
- const isVisible = useMemo(() => observerRef.current ? width > 0 && height > 0 : true, [width, height]);
957
- const paneContext = useMemo(() => ({
958
- isVisible,
959
- id: paneId,
960
- setId: id => setPaneId(id)
961
- }), [paneId, isVisible]);
962
- return React.createElement(PaneContext.Provider, {
963
- value: paneContext
964
- }, React.createElement(StyledPane, _extends({
965
- id: paneId,
966
- ref: mergeRefs([ref, observerRef])
967
- }, props), children));
968
- });
969
- PaneComponent.displayName = 'Pane';
970
- const Pane = PaneComponent;
971
- Pane.Content = Content;
972
- Pane.Splitter = Splitter;
973
- Pane.SplitterButton = SplitterButton;
974
-
975
- export { ALIGN_ITEMS as ARRAY_ALIGN_ITEMS, ALIGN_SELF as ARRAY_ALIGN_SELF, DIRECTION as ARRAY_DIRECTION, JUSTIFY_CONTENT as ARRAY_JUSTIFY_CONTENT, SPACE as ARRAY_SPACE, TEXT_ALIGN as ARRAY_TEXT_ALIGN, WRAP as ARRAY_WRAP, Col, Grid, Pane, PaneProvider, Row };