@carbonplan/components 10.4.0 → 10.5.0

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.
@@ -1,5 +1,5 @@
1
1
  import React, { cloneElement, useCallback, useState, useEffect, useRef } from 'react';
2
- import { Box, Link as Link$1, Grid, IconButton, useColorMode, Container, useThemeUI, Text, Flex, Styled, Input as Input$1, Slider as Slider$1 } from 'theme-ui';
2
+ import { Box, Link as Link$1, Flex, Grid, IconButton, useColorMode, Container, useThemeUI, Text, Styled, Input as Input$1, Slider as Slider$1 } from 'theme-ui';
3
3
  import { transparentize } from '@theme-ui/color';
4
4
  import NextLink from 'next/link';
5
5
  import { Arrow, Sun } from '@carbonplan/icons';
@@ -40,12 +40,14 @@ function _objectWithoutPropertiesLoose(source, excluded) {
40
40
  return target;
41
41
  }
42
42
 
43
- const Badge = (_ref) => {
43
+ const _excluded$g = ["sx", "children"];
44
+
45
+ const Badge = _ref => {
44
46
  let {
45
47
  sx,
46
48
  children
47
49
  } = _ref,
48
- props = _objectWithoutPropertiesLoose(_ref, ["sx", "children"]);
50
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$g);
49
51
 
50
52
  const color = sx && sx.color ? sx.color : 'primary';
51
53
  return /*#__PURE__*/React.createElement(Box, _extends({
@@ -70,6 +72,8 @@ const Badge = (_ref) => {
70
72
  }, children));
71
73
  };
72
74
 
75
+ const _excluded$f = ["href", "children", "internal", "tracking"];
76
+
73
77
  const event = ({
74
78
  action,
75
79
  category,
@@ -88,14 +92,14 @@ const event = ({
88
92
  });
89
93
  };
90
94
 
91
- const Link = (_ref) => {
95
+ const Link = _ref => {
92
96
  let {
93
97
  href,
94
98
  children,
95
99
  internal = false,
96
100
  tracking = false
97
101
  } = _ref,
98
- props = _objectWithoutPropertiesLoose(_ref, ["href", "children", "internal", "tracking"]);
102
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$f);
99
103
 
100
104
  if (internal || href && href.startsWith('/')) {
101
105
  return /*#__PURE__*/React.createElement(NextLink, {
@@ -184,7 +188,9 @@ const getSizeStyles = size => {
184
188
  };
185
189
  };
186
190
 
187
- const Button = (_ref) => {
191
+ const _excluded$e = ["size", "prefix", "suffix", "inverted", "sx", "children", "align", "href", "internal", "tracking"];
192
+
193
+ const Button = _ref => {
188
194
  let {
189
195
  size = 'sm',
190
196
  prefix,
@@ -197,7 +203,7 @@ const Button = (_ref) => {
197
203
  internal,
198
204
  tracking
199
205
  } = _ref,
200
- props = _objectWithoutPropertiesLoose(_ref, ["size", "prefix", "suffix", "inverted", "sx", "children", "align", "href", "internal", "tracking"]);
206
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$e);
201
207
 
202
208
  if (!['xs', 'sm', 'md', 'lg', 'xl'].includes(size)) {
203
209
  throw new Error('Size must be xs, sm, md, lg, or xl');
@@ -371,7 +377,9 @@ const Button = (_ref) => {
371
377
  }
372
378
  };
373
379
 
374
- const Callout = (_ref) => {
380
+ const _excluded$d = ["label", "children", "inverted", "color", "href", "internal", "tracking", "sx"];
381
+
382
+ const Callout = _ref => {
375
383
  let {
376
384
  label,
377
385
  children,
@@ -382,7 +390,7 @@ const Callout = (_ref) => {
382
390
  tracking,
383
391
  sx
384
392
  } = _ref,
385
- props = _objectWithoutPropertiesLoose(_ref, ["label", "children", "inverted", "color", "href", "internal", "tracking", "sx"]);
393
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$d);
386
394
 
387
395
  const baseColor = color || (inverted ? 'secondary' : 'primary');
388
396
  const hoverColor = color ? 'primary' : inverted ? 'primary' : 'secondary';
@@ -461,7 +469,146 @@ const Callout = (_ref) => {
461
469
  }
462
470
  };
463
471
 
464
- const Column = (_ref) => {
472
+ const _excluded$c = ["colormap", "label", "clim", "discrete", "units", "width", "height", "format", "horizontal"];
473
+ const sx$2 = {
474
+ clim: {
475
+ fontFamily: 'mono',
476
+ fontSize: ['9px', 0, 0, 1],
477
+ letterSpacing: 'smallcaps',
478
+ textTransform: 'uppercase'
479
+ }
480
+ };
481
+ const DIMENSIONS = {
482
+ width: ['10px', '16px', '16px', '17px'],
483
+ height: ['80px', '110px', '110px', '130px']
484
+ };
485
+
486
+ const Gradient = ({
487
+ colormap,
488
+ discrete,
489
+ horizontal,
490
+ width,
491
+ height
492
+ }) => {
493
+ const step = 1 / colormap.length * 100;
494
+ const values = colormap.map((d, i) => {
495
+ return `rgb(${d}) ${i * step}% ${discrete && i < colormap.length - 1 ? `${(i + 1) * step}%` : ''}`;
496
+ });
497
+ const css = `linear-gradient(to ${horizontal ? 'right' : 'top'}, ${values.join(',')})`;
498
+ return /*#__PURE__*/React.createElement(Box, {
499
+ sx: _extends({}, horizontal ? {
500
+ width: width || DIMENSIONS.height,
501
+ height: height || DIMENSIONS.width
502
+ } : {
503
+ width: width || DIMENSIONS.width,
504
+ minHeight: height || DIMENSIONS.height
505
+ }, {
506
+ mt: horizontal ? [0, '1px', '1px', 0] : 0,
507
+ border: ({
508
+ colors
509
+ }) => `solid 1px ${colors.hinted}`,
510
+ background: css
511
+ })
512
+ });
513
+ };
514
+
515
+ const Label = ({
516
+ label,
517
+ units,
518
+ horizontal
519
+ }) => /*#__PURE__*/React.createElement(Box, {
520
+ sx: !horizontal && {
521
+ alignSelf: 'flex-end'
522
+ }
523
+ }, /*#__PURE__*/React.createElement(Box, {
524
+ sx: _extends({
525
+ mb: horizontal ? 0 : ['-4px', '-4px', '-4px', '-3px'],
526
+ fontFamily: 'mono',
527
+ fontSize: ['9px', 0, 0, 1],
528
+ letterSpacing: 'smallcaps',
529
+ textTransform: 'uppercase'
530
+ }, horizontal ? {} : {
531
+ writingMode: 'vertical-rl',
532
+ transform: 'rotate(180deg)',
533
+ whiteSpace: 'nowrap',
534
+ display: 'inline-block',
535
+ overflow: 'visible'
536
+ })
537
+ }, label, ' ', /*#__PURE__*/React.createElement(Box, {
538
+ as: "span",
539
+ sx: {
540
+ textTransform: 'none',
541
+ color: 'secondary',
542
+ display: 'inline-block'
543
+ }
544
+ }, units)));
545
+
546
+ const Colorbar = _ref => {
547
+ let {
548
+ colormap,
549
+ label,
550
+ clim,
551
+ discrete,
552
+ units,
553
+ width,
554
+ height,
555
+ format = d => d,
556
+ horizontal = false
557
+ } = _ref,
558
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$c);
559
+
560
+ if (!Array.isArray(colormap)) {
561
+ throw new Error(`expected array for colormap, got '${colormap}'.`);
562
+ }
563
+
564
+ const ClimMin = () => {
565
+ return /*#__PURE__*/React.createElement(Box, {
566
+ sx: _extends({}, sx$2.clim, {
567
+ ml: label ? horizontal ? '10px' : '2px' : 0,
568
+ mr: horizontal ? ['2px', '1px', '1px', '2px'] : 0,
569
+ mb: horizontal ? 0 : ['-2px', '-2px', '-2px', '-3px']
570
+ })
571
+ }, format(clim[0]));
572
+ };
573
+
574
+ const ClimMax = () => {
575
+ return /*#__PURE__*/React.createElement(Box, {
576
+ sx: _extends({}, sx$2.clim, {
577
+ ml: horizontal ? ['2px', '1px', '1px', '2px'] : '2px',
578
+ mt: horizontal ? 0 : ['-2px', '-3px', '-3px', '-3px']
579
+ })
580
+ }, format(clim[1]));
581
+ };
582
+
583
+ return /*#__PURE__*/React.createElement(Flex, {
584
+ sx: _extends({}, props.sx, {
585
+ flexDirection: 'row',
586
+ alignItems: 'center',
587
+ justifyContent: 'flex-start',
588
+ gap: ['3px', '6px', '6px', '7px']
589
+ })
590
+ }, label && /*#__PURE__*/React.createElement(Label, {
591
+ label: label,
592
+ units: units,
593
+ horizontal: horizontal
594
+ }), horizontal && clim && /*#__PURE__*/React.createElement(ClimMin, null), /*#__PURE__*/React.createElement(Gradient, {
595
+ colormap: colormap,
596
+ horizontal: horizontal,
597
+ discrete: discrete,
598
+ width: width,
599
+ height: height
600
+ }), horizontal && clim && /*#__PURE__*/React.createElement(ClimMax, null), !horizontal && /*#__PURE__*/React.createElement(Flex, {
601
+ sx: {
602
+ flexDirection: 'column-reverse',
603
+ justifyContent: 'space-between',
604
+ height: height || DIMENSIONS.height
605
+ }
606
+ }, clim && /*#__PURE__*/React.createElement(ClimMin, null), clim && /*#__PURE__*/React.createElement(ClimMax, null)));
607
+ };
608
+
609
+ const _excluded$b = ["start", "width", "dl", "dr", "children", "sx"];
610
+
611
+ const Column = _ref => {
465
612
  let {
466
613
  start,
467
614
  width,
@@ -470,7 +617,7 @@ const Column = (_ref) => {
470
617
  children,
471
618
  sx
472
619
  } = _ref,
473
- props = _objectWithoutPropertiesLoose(_ref, ["start", "width", "dl", "dr", "children", "sx"]);
620
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$b);
474
621
 
475
622
  start = start || 'auto';
476
623
  width = width || 'auto';
@@ -638,7 +785,7 @@ const Meta = ({
638
785
  }));
639
786
  };
640
787
 
641
- const Logo = (_ref) => {
788
+ const Logo = _ref => {
642
789
  let props = _extends({}, _ref);
643
790
 
644
791
  return /*#__PURE__*/React.createElement(Box, _extends({
@@ -674,14 +821,16 @@ const Logo = (_ref) => {
674
821
  })));
675
822
  };
676
823
 
677
- const Row = (_ref) => {
824
+ const _excluded$a = ["children", "sx", "columns", "gap"];
825
+
826
+ const Row = _ref => {
678
827
  let {
679
828
  children,
680
829
  sx,
681
830
  columns,
682
831
  gap
683
832
  } = _ref,
684
- props = _objectWithoutPropertiesLoose(_ref, ["children", "sx", "columns", "gap"]);
833
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$a);
685
834
 
686
835
  const makeArray = input => {
687
836
  if (!Array.isArray(input)) {
@@ -729,12 +878,14 @@ const Row = (_ref) => {
729
878
  }), children);
730
879
  };
731
880
 
732
- const Menu = (_ref) => {
881
+ const _excluded$9 = ["value", "sx"];
882
+
883
+ const Menu = _ref => {
733
884
  let {
734
885
  value,
735
886
  sx
736
887
  } = _ref,
737
- props = _objectWithoutPropertiesLoose(_ref, ["value", "sx"]);
888
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$9);
738
889
 
739
890
  return /*#__PURE__*/React.createElement(IconButton, _extends({
740
891
  sx: _extends({
@@ -822,12 +973,14 @@ const Menu = (_ref) => {
822
973
  })));
823
974
  };
824
975
 
825
- const Settings = (_ref) => {
976
+ const _excluded$8 = ["value", "sx"];
977
+
978
+ const Settings = _ref => {
826
979
  let {
827
980
  value,
828
981
  sx
829
982
  } = _ref,
830
- props = _objectWithoutPropertiesLoose(_ref, ["value", "sx"]);
983
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$8);
831
984
 
832
985
  return /*#__PURE__*/React.createElement(IconButton, _extends({
833
986
  sx: _extends({
@@ -928,11 +1081,13 @@ const Settings = (_ref) => {
928
1081
  })));
929
1082
  };
930
1083
 
931
- const Dimmer = (_ref) => {
1084
+ const _excluded$7 = ["sx"];
1085
+
1086
+ const Dimmer = _ref => {
932
1087
  let {
933
1088
  sx
934
1089
  } = _ref,
935
- props = _objectWithoutPropertiesLoose(_ref, ["sx"]);
1090
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$7);
936
1091
 
937
1092
  const [colorMode, setColorMode] = useColorMode();
938
1093
  const toggle = useCallback(() => {
@@ -962,7 +1117,7 @@ const Dimmer = (_ref) => {
962
1117
  }));
963
1118
  };
964
1119
 
965
- const sx = {
1120
+ const sx$1 = {
966
1121
  link: (current, label, first = false) => {
967
1122
  return {
968
1123
  width: 'auto',
@@ -1045,12 +1200,12 @@ const Nav = ({
1045
1200
  onClick: () => {
1046
1201
  if (nav === url) setExpanded(false);
1047
1202
  },
1048
- sx: sx.link(nav, url, first)
1203
+ sx: sx$1.link(nav, url, first)
1049
1204
  }, /*#__PURE__*/React.createElement(HoverArrow, null), display));
1050
1205
  } else {
1051
1206
  return /*#__PURE__*/React.createElement(Link$1, {
1052
1207
  href: href,
1053
- sx: sx.link(nav, url, first)
1208
+ sx: sx$1.link(nav, url, first)
1054
1209
  }, /*#__PURE__*/React.createElement(HoverArrow, null), display);
1055
1210
  }
1056
1211
  };
@@ -1219,7 +1374,7 @@ const Header = ({
1219
1374
  })))))));
1220
1375
  };
1221
1376
 
1222
- const Monogram = (_ref) => {
1377
+ const Monogram = _ref => {
1223
1378
  let props = _extends({}, _ref);
1224
1379
 
1225
1380
  return /*#__PURE__*/React.createElement(Box, _extends({
@@ -1537,6 +1692,7 @@ function scrollFraction(window, documnt) {
1537
1692
  return Math.min(window.scrollY / (document.body.offsetHeight - 770), 0.99);
1538
1693
  }
1539
1694
 
1695
+ const _excluded$6 = ["duration", "delay", "children"];
1540
1696
  const fade = keyframes({
1541
1697
  from: {
1542
1698
  opacity: 0
@@ -1546,13 +1702,13 @@ const fade = keyframes({
1546
1702
  }
1547
1703
  });
1548
1704
 
1549
- const FadeIn = (_ref) => {
1705
+ const FadeIn = _ref => {
1550
1706
  let {
1551
1707
  duration = 300,
1552
1708
  delay = 0,
1553
1709
  children
1554
1710
  } = _ref,
1555
- delegated = _objectWithoutPropertiesLoose(_ref, ["duration", "delay", "children"]);
1711
+ delegated = _objectWithoutPropertiesLoose(_ref, _excluded$6);
1556
1712
 
1557
1713
  return /*#__PURE__*/React.createElement(Box, _extends({}, delegated, {
1558
1714
  sx: {
@@ -1865,14 +2021,16 @@ const Expander = ({
1865
2021
  })));
1866
2022
  };
1867
2023
 
1868
- const Tag = (_ref) => {
2024
+ const _excluded$5 = ["label", "value", "sx", "children"];
2025
+
2026
+ const Tag = _ref => {
1869
2027
  let {
1870
2028
  label,
1871
2029
  value,
1872
2030
  sx,
1873
2031
  children
1874
2032
  } = _ref,
1875
- props = _objectWithoutPropertiesLoose(_ref, ["label", "value", "sx", "children"]);
2033
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$5);
1876
2034
 
1877
2035
  const color = sx && sx.color ? sx.color : 'primary';
1878
2036
  const isClickable = props && (props.onClick || props.onDoubleClick);
@@ -1906,7 +2064,8 @@ const Tag = (_ref) => {
1906
2064
  }, props), children);
1907
2065
  };
1908
2066
 
1909
- const sx$1 = {
2067
+ const _excluded$4 = ["values", "setValues", "label", "colors", "showAll", "multiSelect"];
2068
+ const sx = {
1910
2069
  label: {
1911
2070
  fontFamily: 'mono',
1912
2071
  letterSpacing: 'mono',
@@ -1967,7 +2126,7 @@ const updateValues = ({
1967
2126
  }
1968
2127
  };
1969
2128
 
1970
- const Filter = (_ref) => {
2129
+ const Filter = _ref => {
1971
2130
  let {
1972
2131
  values,
1973
2132
  setValues,
@@ -1976,10 +2135,10 @@ const Filter = (_ref) => {
1976
2135
  showAll = false,
1977
2136
  multiSelect = false
1978
2137
  } = _ref,
1979
- props = _objectWithoutPropertiesLoose(_ref, ["values", "setValues", "label", "colors", "showAll", "multiSelect"]);
2138
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
1980
2139
 
1981
2140
  return /*#__PURE__*/React.createElement(Box, props, label && /*#__PURE__*/React.createElement(Box, {
1982
- sx: sx$1.label
2141
+ sx: sx.label
1983
2142
  }, label), /*#__PURE__*/React.createElement(Box, {
1984
2143
  sx: {
1985
2144
  mt: label ? [3] : 0
@@ -2063,13 +2222,15 @@ const Group = ({
2063
2222
  }));
2064
2223
  };
2065
2224
 
2066
- const Input = (_ref) => {
2225
+ const _excluded$3 = ["size", "inverted", "sx"];
2226
+
2227
+ const Input = _ref => {
2067
2228
  let {
2068
2229
  size = 'sm',
2069
2230
  inverted,
2070
2231
  sx
2071
2232
  } = _ref,
2072
- props = _objectWithoutPropertiesLoose(_ref, ["size", "inverted", "sx"]);
2233
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2073
2234
 
2074
2235
  const defaultColor = inverted ? 'secondary' : 'primary';
2075
2236
 
@@ -2117,13 +2278,15 @@ const getProps = test => props => {
2117
2278
  return next;
2118
2279
  };
2119
2280
 
2120
- const Select = (_ref) => {
2281
+ const _excluded$2 = ["children", "size", "sx"];
2282
+
2283
+ const Select = _ref => {
2121
2284
  let {
2122
2285
  children,
2123
2286
  size = 'sm',
2124
2287
  sx
2125
2288
  } = _ref,
2126
- props = _objectWithoutPropertiesLoose(_ref, ["children", "size", "sx"]);
2289
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
2127
2290
 
2128
2291
  const color = sx && sx.color ? sx.color : 'primary';
2129
2292
  const sizeStyles = getSizeStyles(size);
@@ -2210,11 +2373,13 @@ const Select = (_ref) => {
2210
2373
  }));
2211
2374
  };
2212
2375
 
2213
- const Slider = (_ref) => {
2376
+ const _excluded$1 = ["sx"];
2377
+
2378
+ const Slider = _ref => {
2214
2379
  let {
2215
2380
  sx
2216
2381
  } = _ref,
2217
- props = _objectWithoutPropertiesLoose(_ref, ["sx"]);
2382
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
2218
2383
 
2219
2384
  const color = sx && sx.color ? sx.color : 'primary';
2220
2385
  const {
@@ -2354,14 +2519,16 @@ const Table = ({
2354
2519
  })));
2355
2520
  };
2356
2521
 
2357
- const Toggle = (_ref) => {
2522
+ const _excluded = ["value", "onClick", "disabled", "sx"];
2523
+
2524
+ const Toggle = _ref => {
2358
2525
  let {
2359
2526
  value,
2360
2527
  onClick,
2361
2528
  disabled,
2362
2529
  sx
2363
2530
  } = _ref,
2364
- props = _objectWithoutPropertiesLoose(_ref, ["value", "onClick", "disabled", "sx"]);
2531
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
2365
2532
 
2366
2533
  const color = sx && sx.color ? sx.color : 'primary';
2367
2534
  value = disabled ? false : value;
@@ -2505,5 +2672,5 @@ const formatDate = (date, options = defaultOptions) => {
2505
2672
  return [month, day, year].filter(Boolean).join(' ');
2506
2673
  };
2507
2674
 
2508
- export { Badge, Button, Callout, Column, Custom404, Dimmer, Expander, FadeIn, Filter, Footer, Group, Guide, Header, Input, Layout, Link, Logo, Menu, Meta, Monogram, Row, Scrollbar, Select, Settings, Slider, Table, Tag, Toggle, Tracking, Tray, formatDate, getScrollbarWidth };
2675
+ export { Badge, Button, Callout, Colorbar, Column, Custom404, Dimmer, Expander, FadeIn, Filter, Footer, Group, Guide, Header, Input, Layout, Link, Logo, Menu, Meta, Monogram, Row, Scrollbar, Select, Settings, Slider, Table, Tag, Toggle, Tracking, Tray, formatDate, getScrollbarWidth };
2509
2676
  //# sourceMappingURL=index.modern.js.map