@zendeskgarden/react-grid 9.0.0-next.7 → 9.0.0-next.9

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,978 +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': '9.0.0-next.7'
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': '9.0.0-next.7'
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': '9.0.0-next.7'
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': '9.0.0-next.7'
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': '9.0.0-next.7'
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'
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{", ":", ";}&: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': '9.0.0-next.7'
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': '9.0.0-next.7',
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 Row = React.forwardRef((_ref, ref) => {
480
- let {
481
- wrap,
482
- ...props
483
- } = _ref;
484
- const {
485
- gutters,
486
- debug
487
- } = useGridContext();
488
- return React.createElement(StyledRow, _extends({
489
- gutters: gutters,
490
- debug: debug,
491
- wrapAll: wrap,
492
- ref: ref
493
- }, props));
494
- });
495
- Row.displayName = 'Row';
496
- Row.propTypes = {
497
- alignItems: PropTypes.oneOf(ALIGN_ITEMS),
498
- alignItemsXs: PropTypes.oneOf(ALIGN_ITEMS),
499
- alignItemsSm: PropTypes.oneOf(ALIGN_ITEMS),
500
- alignItemsMd: PropTypes.oneOf(ALIGN_ITEMS),
501
- alignItemsLg: PropTypes.oneOf(ALIGN_ITEMS),
502
- alignItemsXl: PropTypes.oneOf(ALIGN_ITEMS),
503
- justifyContent: PropTypes.oneOf(JUSTIFY_CONTENT),
504
- justifyContentXs: PropTypes.oneOf(JUSTIFY_CONTENT),
505
- justifyContentSm: PropTypes.oneOf(JUSTIFY_CONTENT),
506
- justifyContentMd: PropTypes.oneOf(JUSTIFY_CONTENT),
507
- justifyContentLg: PropTypes.oneOf(JUSTIFY_CONTENT),
508
- justifyContentXl: PropTypes.oneOf(JUSTIFY_CONTENT),
509
- wrap: PropTypes.oneOf(WRAP),
510
- wrapXs: PropTypes.oneOf(WRAP),
511
- wrapSm: PropTypes.oneOf(WRAP),
512
- wrapMd: PropTypes.oneOf(WRAP),
513
- wrapLg: PropTypes.oneOf(WRAP),
514
- wrapXl: PropTypes.oneOf(WRAP)
515
- };
516
-
517
- const GridComponent = React.forwardRef((_ref, ref) => {
518
- let {
519
- columns,
520
- debug,
521
- ...props
522
- } = _ref;
523
- const value = useMemo(() => ({
524
- columns,
525
- gutters: props.gutters,
526
- debug
527
- }), [columns, props.gutters, debug]);
528
- return React.createElement(GridContext.Provider, {
529
- value: value
530
- }, React.createElement(StyledGrid, _extends({
531
- debug: debug,
532
- ref: ref
533
- }, props)));
534
- });
535
- GridComponent.displayName = 'Grid';
536
- GridComponent.propTypes = {
537
- columns: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
538
- gutters: PropTypes.oneOf(SPACE),
539
- debug: PropTypes.bool
540
- };
541
- GridComponent.defaultProps = {
542
- columns: 12,
543
- gutters: 'md'
544
- };
545
- const Grid = GridComponent;
546
- Grid.Row = Row;
547
- Grid.Col = Col;
548
-
549
- const PaneProviderContext = createContext({});
550
- const usePaneProviderContextData = providerId => {
551
- const context = useContext(PaneProviderContext);
552
- const id = providerId || context.providerId;
553
- return id && context.contextData ? context.contextData[id] : undefined;
554
- };
555
- const usePaneProviderContext = () => useContext(PaneProviderContext);
556
-
557
- const getPixelsPerFr = (totalFrs, totalDimension) => {
558
- return totalDimension / totalFrs;
559
- };
560
- const convertToPixels = (values, pixelsPerFr) => {
561
- return Object.entries(values).reduce((prev, _ref) => {
562
- let [key, value] = _ref;
563
- prev[key] = value * pixelsPerFr;
564
- return prev;
565
- }, {});
566
- };
567
- const PaneProvider = _ref2 => {
568
- let {
569
- id,
570
- totalPanesWidth,
571
- totalPanesHeight,
572
- defaultRowValues,
573
- defaultColumnValues,
574
- rowValues,
575
- columnValues,
576
- onChange,
577
- children
578
- } = _ref2;
579
- const isControlled = rowValues !== undefined && rowValues !== null && columnValues !== undefined && columnValues !== null;
580
- const [rowState, setRowState] = useState(defaultRowValues || {});
581
- const [columnState, setColumnState] = useState(defaultColumnValues || {});
582
- const rowsTrack = isControlled ? rowValues : rowState;
583
- const columnsTrack = isControlled ? columnValues : columnState;
584
- const setRowsTrack = useCallback(values => {
585
- if (isControlled && onChange) {
586
- return onChange(values(rowsTrack), columnsTrack);
587
- }
588
- return setRowState(values);
589
- }, [isControlled, onChange, setRowState, columnsTrack, rowsTrack]);
590
- const setColumnsTrack = useCallback(values => {
591
- if (isControlled && onChange) {
592
- return onChange(rowsTrack, values(columnsTrack));
593
- }
594
- return setColumnState(values);
595
- }, [isControlled, onChange, setColumnState, rowsTrack, columnsTrack]);
596
- const totalFractions = useMemo(() => ({
597
- rows: Object.values(rowsTrack).reduce((prev, value) => value + prev, 0),
598
- columns: Object.values(columnsTrack).reduce((prev, value) => value + prev, 0)
599
- }), [rowsTrack, columnsTrack]);
600
- const pixelsPerFr = useMemo(() => ({
601
- rows: getPixelsPerFr(totalFractions.rows, totalPanesHeight),
602
- columns: getPixelsPerFr(totalFractions.columns, totalPanesWidth)
603
- }), [totalFractions, totalPanesHeight, totalPanesWidth]);
604
- const layoutStateInPixels = useMemo(() => ({
605
- rows: convertToPixels(rowsTrack, pixelsPerFr.rows),
606
- columns: convertToPixels(columnsTrack, pixelsPerFr.columns)
607
- }), [rowsTrack, columnsTrack, pixelsPerFr]);
608
- const layoutIndices = useMemo(() => {
609
- const rowArray = Object.keys(rowsTrack);
610
- const columnArray = Object.keys(columnsTrack);
611
- const rows = rowArray.reduce((prev, key, index) => {
612
- prev[key] = index;
613
- return prev;
614
- }, {});
615
- const columns = columnArray.reduce((prev, key, index) => {
616
- prev[key] = index;
617
- return prev;
618
- }, {});
619
- return {
620
- rows,
621
- columns,
622
- rowArray,
623
- columnArray
624
- };
625
- }, [rowsTrack, columnsTrack]);
626
- const setRowValue = useCallback((isTop, splitterId, value) => {
627
- const {
628
- rows,
629
- rowArray
630
- } = layoutIndices;
631
- const stealFromTraversal = isTop ? -1 : 1;
632
- const addToTraversal = 0;
633
- setRowsTrack(state => {
634
- const oldValue = rowsTrack[splitterId];
635
- const stealFromIndex = rows[splitterId] + stealFromTraversal;
636
- const addToIndex = rows[splitterId] + addToTraversal;
637
- const stealFromKey = rowArray[stealFromIndex];
638
- const addToKey = rowArray[addToIndex];
639
- const difference = oldValue - value;
640
- const nextState = {
641
- ...state
642
- };
643
- nextState[addToKey] = rowsTrack[addToKey] - difference;
644
- nextState[stealFromKey] = rowsTrack[stealFromKey] + difference;
645
- return nextState;
646
- });
647
- }, [layoutIndices, rowsTrack, setRowsTrack]);
648
- const setColumnValue = useCallback((isStart, splitterId, value) => {
649
- const {
650
- columns,
651
- columnArray
652
- } = layoutIndices;
653
- const stealFromTraversal = isStart ? -1 : 1;
654
- const addToTraversal = 0;
655
- setColumnsTrack(state => {
656
- const stealFromIndex = columns[splitterId] + stealFromTraversal;
657
- const addToIndex = columns[splitterId] + addToTraversal;
658
- const oldValue = columnsTrack[splitterId];
659
- const stealFromKey = columnArray[stealFromIndex];
660
- const addToKey = columnArray[addToIndex];
661
- const difference = oldValue - value;
662
- const nextState = {
663
- ...state
664
- };
665
- nextState[addToKey] = columnsTrack[addToKey] - difference;
666
- nextState[stealFromKey] = columnsTrack[stealFromKey] + difference;
667
- return nextState;
668
- });
669
- }, [layoutIndices, columnsTrack, setColumnsTrack]);
670
- const getColumnValue = useCallback((splitterKey, isPixels) => {
671
- if (isPixels) {
672
- return layoutStateInPixels.columns[splitterKey];
673
- }
674
- return columnsTrack[splitterKey];
675
- }, [columnsTrack, layoutStateInPixels]);
676
- const getRowValue = useCallback((splitterKey, isPixels) => {
677
- if (isPixels) {
678
- return layoutStateInPixels.rows[splitterKey];
679
- }
680
- return rowsTrack[splitterKey];
681
- }, [rowsTrack, layoutStateInPixels]);
682
- const getGridTemplateColumns = useCallback(isPixels => {
683
- const {
684
- columnArray
685
- } = layoutIndices;
686
- if (isPixels) {
687
- return columnArray.map(col => `${layoutStateInPixels.columns[col]}px`).join(' ');
688
- }
689
- return columnArray.map(col => `${columnsTrack[col]}fr`).join(' ');
690
- }, [layoutIndices, columnsTrack, layoutStateInPixels]);
691
- const getGridTemplateRows = useCallback(isPixels => {
692
- const {
693
- rowArray
694
- } = layoutIndices;
695
- if (isPixels) {
696
- return rowArray.map(row => `${layoutStateInPixels.rows[row]}px`).join(' ');
697
- }
698
- return rowArray.map(row => `${rowsTrack[row]}fr`).join(' ');
699
- }, [layoutIndices, rowsTrack, layoutStateInPixels]);
700
- const providerId = useId(id);
701
- const parentPaneProviderContext = usePaneProviderContext();
702
- const paneProviderContext = useMemo(() => providerId ? {
703
- providerId,
704
- contextData: {
705
- ...parentPaneProviderContext.contextData,
706
- [providerId]: {
707
- columnState,
708
- rowState,
709
- setRowValue,
710
- setColumnValue,
711
- getRowValue,
712
- getColumnValue,
713
- totalPanesHeight,
714
- totalPanesWidth,
715
- pixelsPerFr
716
- }
717
- }
718
- } : {}, [providerId, parentPaneProviderContext, rowState, columnState, setRowValue, setColumnValue, getRowValue, getColumnValue, totalPanesHeight, totalPanesWidth, pixelsPerFr]);
719
- return React.createElement(PaneProviderContext.Provider, {
720
- value: paneProviderContext
721
- }, children?.({
722
- id: providerId,
723
- getRowValue,
724
- getColumnValue,
725
- getGridTemplateColumns,
726
- getGridTemplateRows
727
- }));
728
- };
729
- PaneProvider.displayName = 'PaneProvider';
730
- PaneProvider.propTypes = {
731
- id: PropTypes.string,
732
- totalPanesWidth: PropTypes.number.isRequired,
733
- totalPanesHeight: PropTypes.number.isRequired,
734
- defaultRowValues: PropTypes.object,
735
- defaultColumnValues: PropTypes.object,
736
- rowValues: PropTypes.object,
737
- columnValues: PropTypes.object,
738
- onChange: PropTypes.func,
739
- children: PropTypes.func
740
- };
741
-
742
- const PaneContext = createContext({
743
- setId: () => undefined
744
- });
745
- const usePaneContext = () => {
746
- return useContext(PaneContext);
747
- };
748
-
749
- const PaneSplitterContext = createContext({
750
- orientation: 'start',
751
- min: 0,
752
- max: 0,
753
- layoutKey: '',
754
- valueNow: 0,
755
- size: 0,
756
- isRow: false
757
- });
758
- const usePaneSplitterContext = () => {
759
- return useContext(PaneSplitterContext);
760
- };
761
-
762
- const paneToSplitterOrientation = {
763
- start: 'vertical',
764
- end: 'vertical',
765
- top: 'horizontal',
766
- bottom: 'horizontal'
767
- };
768
- const orientationToDimension = {
769
- start: 'columns',
770
- end: 'columns',
771
- top: 'rows',
772
- bottom: 'rows'
773
- };
774
- const SplitterComponent = forwardRef((_ref, ref) => {
775
- let {
776
- children,
777
- providerId,
778
- layoutKey,
779
- min,
780
- max,
781
- orientation,
782
- isFixed,
783
- onMouseDown,
784
- onTouchStart,
785
- onKeyDown,
786
- onClick,
787
- ...props
788
- } = _ref;
789
- const paneProviderContext = usePaneProviderContextData(providerId);
790
- const paneContext = usePaneContext();
791
- const themeContext = useContext(ThemeContext);
792
- const environment = useDocument(themeContext);
793
- const isRow = orientationToDimension[orientation] === 'rows';
794
- const separatorRef = useRef(null);
795
- const splitterOrientation = paneToSplitterOrientation[orientation || 'end'];
796
- const pixelsPerFr = paneProviderContext ? paneProviderContext.pixelsPerFr[orientationToDimension[orientation]] : 0;
797
- const value = isRow ? paneProviderContext?.getRowValue(layoutKey, true) : paneProviderContext?.getColumnValue(layoutKey, true);
798
- const valueInFr = isRow ? paneProviderContext?.getRowValue(layoutKey) : paneProviderContext?.getColumnValue(layoutKey);
799
- const {
800
- getSeparatorProps,
801
- getPrimaryPaneProps
802
- } = useSplitter({
803
- orientation: splitterOrientation,
804
- isLeading: orientation === 'start' || orientation === 'top',
805
- min: min * pixelsPerFr,
806
- max: max * pixelsPerFr,
807
- rtl: themeContext.rtl,
808
- isFixed,
809
- environment,
810
- onChange: valueNow => {
811
- if (isRow) {
812
- return paneProviderContext?.setRowValue(orientation === 'top', layoutKey, valueNow / pixelsPerFr);
813
- }
814
- return paneProviderContext?.setColumnValue(orientation === 'start', layoutKey, valueNow / pixelsPerFr);
815
- },
816
- valueNow: value,
817
- separatorRef
818
- });
819
- useEffect(() => {
820
- if (!paneContext.id) {
821
- paneContext.setId(getPrimaryPaneProps().id);
822
- }
823
- }, [paneContext, getPrimaryPaneProps]);
824
- const ariaLabel = useText(SplitterComponent, props, 'aria-label', `${splitterOrientation} splitter`);
825
- const separatorProps = getSeparatorProps({
826
- 'aria-controls': paneContext.id,
827
- 'aria-label': ariaLabel,
828
- onMouseDown,
829
- onTouchStart,
830
- onKeyDown,
831
- onClick
832
- });
833
- const size = isRow ? separatorRef.current?.clientWidth : separatorRef.current?.clientHeight;
834
- return React.createElement(PaneSplitterContext.Provider, {
835
- value: useMemo(() => ({
836
- orientation,
837
- layoutKey,
838
- min,
839
- max,
840
- valueNow: valueInFr,
841
- size,
842
- isRow
843
- }), [orientation, layoutKey, min, max, valueInFr, size, isRow])
844
- }, React.createElement(StyledPaneSplitter, _extends({
845
- isFixed: isFixed,
846
- orientation: orientation
847
- }, separatorProps, props, {
848
- ref: mergeRefs([separatorRef, ref])
849
- })), children );
850
- });
851
- SplitterComponent.displayName = 'Pane.Splitter';
852
- SplitterComponent.propTypes = {
853
- layoutKey: PropTypes.string.isRequired,
854
- min: PropTypes.number.isRequired,
855
- max: PropTypes.number.isRequired,
856
- orientation: PropTypes.oneOf(ORIENTATION),
857
- isFixed: PropTypes.bool
858
- };
859
- SplitterComponent.defaultProps = {
860
- orientation: 'end'
861
- };
862
- const Splitter = SplitterComponent;
863
-
864
- const ContentComponent = forwardRef((props, ref) => {
865
- const {
866
- isVisible
867
- } = usePaneContext();
868
- return React.createElement(StyledPaneContent, _extends({
869
- hidden: !isVisible,
870
- ref: ref
871
- }, props));
872
- });
873
- ContentComponent.displayName = 'Pane.Content';
874
- const Content = ContentComponent;
875
-
876
- const SplitterButtonComponent = forwardRef((props, ref) => {
877
- const {
878
- label,
879
- placement: defaultPlacement
880
- } = props;
881
- const {
882
- orientation,
883
- layoutKey,
884
- min,
885
- max,
886
- isRow,
887
- valueNow,
888
- size,
889
- providerId
890
- } = usePaneSplitterContext();
891
- const paneProviderContext = usePaneProviderContextData(providerId);
892
- const isTop = orientation === 'top';
893
- const isStart = orientation === 'start';
894
- const isMin = valueNow === min;
895
- let placement = defaultPlacement;
896
- if (!defaultPlacement) {
897
- if (isRow) {
898
- placement = 'center';
899
- } else {
900
- placement = 'start';
901
- }
902
- }
903
- const setValue = useCallback(value => {
904
- if (isRow) {
905
- paneProviderContext.setRowValue(isTop, layoutKey, value);
906
- } else {
907
- paneProviderContext.setColumnValue(isStart, layoutKey, value);
908
- }
909
- }, [isRow, isTop, isStart, layoutKey, paneProviderContext]);
910
- const onClick = composeEventHandlers(props.onClick, () => {
911
- if (isMin) {
912
- setValue(max);
913
- } else {
914
- setValue(min);
915
- }
916
- });
917
- const onKeyDown = composeEventHandlers(props.onKeyDown, event => event.stopPropagation()
918
- );
919
- const onMouseDown = composeEventHandlers(props.onMouseDown, event => event.stopPropagation()
920
- );
921
- return React.createElement(StyledPaneSplitterButtonContainer, {
922
- orientation: orientation,
923
- placement: placement,
924
- splitterSize: size || 0
925
- }, React.createElement(Tooltip, {
926
- content: label,
927
- zIndex: 2,
928
- style: {
929
- cursor: 'default'
930
- },
931
- onMouseDown: e => e.stopPropagation()
932
- }, React.createElement(StyledPaneSplitterButton, _extends({
933
- "aria-label": label
934
- }, props, {
935
- orientation: orientation,
936
- isRotated: isMin,
937
- ref: ref,
938
- onClick: onClick,
939
- onKeyDown: onKeyDown,
940
- onMouseDown: onMouseDown
941
- }))));
942
- });
943
- SplitterButtonComponent.displayName = 'Pane.SplitterButton';
944
- const SplitterButton = SplitterButtonComponent;
945
-
946
- const PaneComponent = forwardRef((_ref, ref) => {
947
- let {
948
- children,
949
- ...props
950
- } = _ref;
951
- const [paneId, setPaneId] = useState();
952
- const observerRef = useRef(null);
953
- const {
954
- width = 0,
955
- height = 0
956
- } = useResizeObserver({
957
- ref: observerRef
958
- });
959
- const isVisible = useMemo(() => observerRef.current ? width > 0 && height > 0 : true, [width, height]);
960
- const paneContext = useMemo(() => ({
961
- isVisible,
962
- id: paneId,
963
- setId: id => setPaneId(id)
964
- }), [paneId, isVisible]);
965
- return React.createElement(PaneContext.Provider, {
966
- value: paneContext
967
- }, React.createElement(StyledPane, _extends({
968
- id: paneId,
969
- ref: mergeRefs([ref, observerRef])
970
- }, props), children));
971
- });
972
- PaneComponent.displayName = 'Pane';
973
- const Pane = PaneComponent;
974
- Pane.Content = Content;
975
- Pane.Splitter = Splitter;
976
- Pane.SplitterButton = SplitterButton;
977
-
978
- export { ALIGN_ITEMS, ALIGN_SELF, Col, DIRECTION, Grid, JUSTIFY_CONTENT, Pane, PaneProvider, Row, SPACE, TEXT_ALIGN, WRAP };