@planningcenter/tapestry-react 2.5.0 → 2.6.0-rc.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.
@@ -260,7 +260,7 @@ function Button(_ref) {
260
260
  }
261
261
 
262
262
  if (type && restProps.as && restProps.as !== "button") {
263
- throw Error("Tapestry-React: <Button/> type prop is only supported by <button> and not <" + restProps.as + ">.");
263
+ console.log("Tapestry-React: <Button/> type prop is only supported by <button> and not <" + restProps.as + ">.");
264
264
  }
265
265
  }
266
266
 
@@ -85,24 +85,8 @@ function Checkbox(_ref) {
85
85
  wrapperProps = _useAccessibilityViol.wrapperProps;
86
86
 
87
87
  (0, _react.useLayoutEffect)(function () {
88
- function findParent(node, findMatch) {
89
- if (node && node !== document.documentElement) {
90
- var matchFound = findMatch(node.parentNode);
91
-
92
- if (matchFound) {
93
- return node.parentNode;
94
- } else {
95
- return findParent(node.parentNode, findMatch);
96
- }
97
- } else {
98
- return null;
99
- }
100
- }
101
-
102
88
  if (label === undefined) {
103
- var labelParent = findParent(ref.current, function (parentNode) {
104
- return parentNode.tagName === 'LABEL';
105
- });
89
+ var labelParent = ref.current.closest('label') !== null;
106
90
 
107
91
  if (!labelParent) {
108
92
  setNeedsParentLabel(true);
@@ -75,9 +75,7 @@ var NavButton = function NavButton(_ref) {
75
75
  };
76
76
 
77
77
  function Pagination(_ref2) {
78
- var _ref2$activeColor = _ref2.activeColor,
79
- activeColor = _ref2$activeColor === void 0 ? '#5b8bf7' : _ref2$activeColor,
80
- currentPage = _ref2.currentPage,
78
+ var currentPage = _ref2.currentPage,
81
79
  _ref2$onPageChange = _ref2.onPageChange,
82
80
  onPageChange = _ref2$onPageChange === void 0 ? function () {
83
81
  return null;
@@ -85,11 +83,19 @@ function Pagination(_ref2) {
85
83
  visiblePages = _ref2.visiblePages,
86
84
  _ref2$totalPages = _ref2.totalPages,
87
85
  totalPages = _ref2$totalPages === void 0 ? 0 : _ref2$totalPages,
88
- restProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, ["activeColor", "currentPage", "onPageChange", "visiblePages", "totalPages"]);
86
+ restProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, ["currentPage", "onPageChange", "visiblePages", "totalPages"]);
89
87
 
90
88
  var _useThemeValue = (0, _system.useThemeValue)('breakpoints'),
91
89
  xsBreakpoint = _useThemeValue.xs;
92
90
 
91
+ var _useThemeProps = (0, _system.useThemeProps)('pagination', _objectSpread({}, restProps)),
92
+ _useThemeProps$active = _useThemeProps.activeColor,
93
+ activeColor = _useThemeProps$active === void 0 ? '#5b8bf7' : _useThemeProps$active,
94
+ navButtonProps = _useThemeProps.navButtonProps,
95
+ pageLinkProps = _useThemeProps.pageLinkProps,
96
+ activePageLinkProps = _useThemeProps.activePageLinkProps,
97
+ themeProps = (0, _objectWithoutPropertiesLoose2["default"])(_useThemeProps, ["activeColor", "navButtonProps", "pageLinkProps", "activePageLinkProps"]);
98
+
93
99
  var currentWidth = (0, _windowSize.useWindowWidth)();
94
100
 
95
101
  function renderGap(key) {
@@ -125,10 +131,10 @@ function Pagination(_ref2) {
125
131
  square: true,
126
132
  title: number,
127
133
  variant: isCurrentPage ? 'fill' : 'naked'
128
- }, isCurrentPage && {
134
+ }, pageLinkProps, isCurrentPage && _objectSpread({
129
135
  backgroundColor: activeColor,
130
136
  color: '#fff'
131
- }));
137
+ }, activePageLinkProps)));
132
138
  }
133
139
 
134
140
  function renderPageLinks() {
@@ -151,22 +157,22 @@ function Pagination(_ref2) {
151
157
  shrink: 0,
152
158
  spacing: 0.5,
153
159
  width: "100%"
154
- }, restProps), /*#__PURE__*/_react["default"].createElement(_Group["default"], {
160
+ }, themeProps), /*#__PURE__*/_react["default"].createElement(_Group["default"], {
155
161
  spacing: 0.5
156
- }, /*#__PURE__*/_react["default"].createElement(NavButton, {
162
+ }, /*#__PURE__*/_react["default"].createElement(NavButton, (0, _extends2["default"])({
157
163
  disabled: currentPage === 1,
158
164
  iconName: "general.leftChevron",
159
165
  onClick: onPageChange.bind(null, currentPage - 1),
160
166
  tooltip: {
161
167
  title: 'Previous Page'
162
168
  }
163
- }), /*#__PURE__*/_react["default"].createElement(NavButton, {
169
+ }, navButtonProps)), /*#__PURE__*/_react["default"].createElement(NavButton, (0, _extends2["default"])({
164
170
  disabled: currentPage === totalPages,
165
171
  iconName: "general.rightChevron",
166
172
  onClick: onPageChange.bind(null, currentPage + 1),
167
173
  tooltip: {
168
174
  title: 'Next Page'
169
175
  }
170
- })), renderPageLinks());
176
+ }, navButtonProps))), renderPageLinks());
171
177
  }
172
178
  }
@@ -75,6 +75,8 @@ function mergeThemes(a, b) {
75
75
  }
76
76
 
77
77
  function ThemeProvider(_ref) {
78
+ var _ref2;
79
+
78
80
  var _ref$theme = _ref.theme,
79
81
  theme = _ref$theme === void 0 ? emptyTheme : _ref$theme,
80
82
  children = _ref.children;
@@ -87,7 +89,7 @@ function ThemeProvider(_ref) {
87
89
 
88
90
  (0, _react.useLayoutEffect)(function () {
89
91
  var nextTheme = mergeThemes(_defaultTheme["default"], theme);
90
- (0, _styles.setRootStyles)((0, _utils.objectToCSSProperties)('colors', nextTheme.colors));
92
+ (0, _styles.setRootStyles)(nextTheme.id, (0, _utils.objectToCSSProperties)('colors', nextTheme.colors));
91
93
 
92
94
  if (!(0, _utils.shallowEqual)(mergedTheme, nextTheme)) {
93
95
  setMergedTheme(nextTheme);
@@ -97,7 +99,7 @@ function ThemeProvider(_ref) {
97
99
  value: cache
98
100
  }, /*#__PURE__*/_react["default"].createElement(_react2.ThemeProvider, {
99
101
  theme: mergedTheme
100
- }, children));
102
+ }, /*#__PURE__*/_react["default"].createElement("div", (_ref2 = {}, _ref2["" + (0, _styles.getThemeDataAttribute)(mergedTheme.id)] = true, _ref2), children)));
101
103
  }
102
104
 
103
105
  ThemeProvider.cache = cache;
@@ -1,23 +1,33 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
+ exports.getThemeDataAttribute = getThemeDataAttribute;
4
5
  exports.styleReset = exports.defaultColorProperties = exports.setRootStyles = void 0;
5
6
 
6
7
  var _system = require("../system");
7
8
 
8
9
  var _utils = require("../utils");
9
10
 
10
- var getRootStyles = function getRootStyles(styles) {
11
+ function getThemeDataAttribute(themeId) {
12
+ if (themeId) {
13
+ return "data-tapestry-react-theme-provider-" + themeId;
14
+ } else {
15
+ return 'data-tapestry-react-theme-provider';
16
+ }
17
+ }
18
+
19
+ var getRootStyles = function getRootStyles(id, styles) {
11
20
  var styleString = Object.keys(styles).map(function (key) {
12
21
  return key + ": " + styles[key];
13
22
  }).join('; ');
14
- return ":root { " + styleString + " }";
23
+ return "[" + getThemeDataAttribute(id) + "] { " + styleString + " }";
15
24
  };
16
25
 
17
- var setRootStyles = function setRootStyles(styles) {
18
- var styleElement = document.getElementById('tapestry-react-style');
26
+ var setRootStyles = function setRootStyles(themeId, styles) {
27
+ ensureStyleElement(themeId);
28
+ var styleElement = document.getElementById("tapestry-react-style-" + themeId);
19
29
  var sheet = styleElement.sheet;
20
- var styleString = getRootStyles(styles);
30
+ var styleString = getRootStyles(themeId, styles);
21
31
  sheet.deleteRule(0);
22
32
  sheet.insertRule(styleString, 0);
23
33
  };
@@ -25,16 +35,21 @@ var setRootStyles = function setRootStyles(styles) {
25
35
  exports.setRootStyles = setRootStyles;
26
36
  var defaultColorProperties = (0, _utils.objectToCSSProperties)('colors', (0, _system.flattenPalette)(_system.defaultTheme.colors));
27
37
  exports.defaultColorProperties = defaultColorProperties;
28
- var styleReset = ("\n" + getRootStyles(defaultColorProperties) + "\n\n.tapestry-react-reset {\n appearance: none;\n box-sizing: border-box;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';\n font-weight: 400;\n text-decoration: none;\n flex: 0 0 auto;\n min-width: 0px;\n min-height: 0px;\n padding: 0px;\n margin: 0px;\n border: 0px solid transparent;\n background-color: transparent;\n color: inherit;\n}\n\n.tapestry-react-reset::-moz-focus-inner {\n padding: 0px;\n border: 0px;\n}\n\n.tapestry-react-reset:focus:not(.focus-visible) {\n outline: 0px;\n}\n" // minify string
38
+ var styleReset = ("\n" + getRootStyles(null, defaultColorProperties) + "\n\n.tapestry-react-reset {\n appearance: none;\n box-sizing: border-box;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';\n font-weight: 400;\n text-decoration: none;\n flex: 0 0 auto;\n min-width: 0px;\n min-height: 0px;\n padding: 0px;\n margin: 0px;\n border: 0px solid transparent;\n background-color: transparent;\n color: inherit;\n}\n\n.tapestry-react-reset::-moz-focus-inner {\n padding: 0px;\n border: 0px;\n}\n\n.tapestry-react-reset:focus:not(.focus-visible) {\n outline: 0px;\n}\n" // minify string
29
39
  ).replace(/\n/g, '').replace(/\s\s+/g, ' '); // we use our own global style implementation in place of Emotion Global
30
40
  // so we can have more control over when styles are injected since multiple
31
41
  // Providers can be used on a page
32
42
 
33
43
  exports.styleReset = styleReset;
34
44
 
35
- if (typeof window !== 'undefined' && !document.getElementById('tapestry-react-style')) {
36
- var styleElement = document.createElement('style');
37
- styleElement.id = 'tapestry-react-style';
38
- styleElement.innerHTML = styleReset;
39
- document.head.insertAdjacentElement('afterbegin', styleElement);
45
+ function ensureStyleElement(themeId) {
46
+ // we use our own global style implementation in place of Emotion Global
47
+ // so we can have more control over when styles are injected since multiple
48
+ // Providers can be used on a page
49
+ if (typeof window !== 'undefined' && !document.getElementById("tapestry-react-style-" + themeId)) {
50
+ var styleElement = document.createElement('style');
51
+ styleElement.id = "tapestry-react-style-" + themeId;
52
+ styleElement.innerHTML = styleReset;
53
+ document.head.insertAdjacentElement('afterbegin', styleElement);
54
+ }
40
55
  }
@@ -23,6 +23,7 @@ var controlStyles = {
23
23
  checkedStroke: 'primary'
24
24
  };
25
25
  var defaultTheme = {
26
+ id: 'default',
26
27
  boxSizes: _boxSizes.boxSizes,
27
28
  colors: _colors.colors,
28
29
  icons: {
@@ -245,7 +245,7 @@ export function Button(_ref) {
245
245
  }
246
246
 
247
247
  if (type && restProps.as && restProps.as !== "button") {
248
- throw Error("Tapestry-React: <Button/> type prop is only supported by <button> and not <" + restProps.as + ">.");
248
+ console.log("Tapestry-React: <Button/> type prop is only supported by <button> and not <" + restProps.as + ">.");
249
249
  }
250
250
  }
251
251
 
@@ -65,24 +65,8 @@ function Checkbox(_ref) {
65
65
  wrapperProps = _useAccessibilityViol.wrapperProps;
66
66
 
67
67
  useLayoutEffect(function () {
68
- function findParent(node, findMatch) {
69
- if (node && node !== document.documentElement) {
70
- var matchFound = findMatch(node.parentNode);
71
-
72
- if (matchFound) {
73
- return node.parentNode;
74
- } else {
75
- return findParent(node.parentNode, findMatch);
76
- }
77
- } else {
78
- return null;
79
- }
80
- }
81
-
82
68
  if (label === undefined) {
83
- var labelParent = findParent(ref.current, function (parentNode) {
84
- return parentNode.tagName === 'LABEL';
85
- });
69
+ var labelParent = ref.current.closest('label') !== null;
86
70
 
87
71
  if (!labelParent) {
88
72
  setNeedsParentLabel(true);
@@ -14,7 +14,7 @@ import StackView from '../StackView';
14
14
  import { range } from '../utils';
15
15
  import { parseColor } from '../system/utils';
16
16
  import { useWindowWidth } from '@react-hook/window-size';
17
- import { useThemeValue } from '../system';
17
+ import { useThemeValue, useThemeProps } from '../system';
18
18
 
19
19
  function getVisiblePages(currentPage, totalPages, visiblePages) {
20
20
  var start = Math.max(1, Math.min(totalPages - visiblePages + 1, Math.floor(currentPage - visiblePages / 2 + 1)));
@@ -59,9 +59,7 @@ var NavButton = function NavButton(_ref) {
59
59
  };
60
60
 
61
61
  export default function Pagination(_ref2) {
62
- var _ref2$activeColor = _ref2.activeColor,
63
- activeColor = _ref2$activeColor === void 0 ? '#5b8bf7' : _ref2$activeColor,
64
- currentPage = _ref2.currentPage,
62
+ var currentPage = _ref2.currentPage,
65
63
  _ref2$onPageChange = _ref2.onPageChange,
66
64
  onPageChange = _ref2$onPageChange === void 0 ? function () {
67
65
  return null;
@@ -69,11 +67,19 @@ export default function Pagination(_ref2) {
69
67
  visiblePages = _ref2.visiblePages,
70
68
  _ref2$totalPages = _ref2.totalPages,
71
69
  totalPages = _ref2$totalPages === void 0 ? 0 : _ref2$totalPages,
72
- restProps = _objectWithoutPropertiesLoose(_ref2, ["activeColor", "currentPage", "onPageChange", "visiblePages", "totalPages"]);
70
+ restProps = _objectWithoutPropertiesLoose(_ref2, ["currentPage", "onPageChange", "visiblePages", "totalPages"]);
73
71
 
74
72
  var _useThemeValue = useThemeValue('breakpoints'),
75
73
  xsBreakpoint = _useThemeValue.xs;
76
74
 
75
+ var _useThemeProps = useThemeProps('pagination', _objectSpread({}, restProps)),
76
+ _useThemeProps$active = _useThemeProps.activeColor,
77
+ activeColor = _useThemeProps$active === void 0 ? '#5b8bf7' : _useThemeProps$active,
78
+ navButtonProps = _useThemeProps.navButtonProps,
79
+ pageLinkProps = _useThemeProps.pageLinkProps,
80
+ activePageLinkProps = _useThemeProps.activePageLinkProps,
81
+ themeProps = _objectWithoutPropertiesLoose(_useThemeProps, ["activeColor", "navButtonProps", "pageLinkProps", "activePageLinkProps"]);
82
+
77
83
  var currentWidth = useWindowWidth();
78
84
 
79
85
  function renderGap(key) {
@@ -109,10 +115,10 @@ export default function Pagination(_ref2) {
109
115
  square: true,
110
116
  title: number,
111
117
  variant: isCurrentPage ? 'fill' : 'naked'
112
- }, isCurrentPage && {
118
+ }, pageLinkProps, isCurrentPage && _objectSpread({
113
119
  backgroundColor: activeColor,
114
120
  color: '#fff'
115
- }));
121
+ }, activePageLinkProps)));
116
122
  }
117
123
 
118
124
  function renderPageLinks() {
@@ -135,22 +141,22 @@ export default function Pagination(_ref2) {
135
141
  shrink: 0,
136
142
  spacing: 0.5,
137
143
  width: "100%"
138
- }, restProps), /*#__PURE__*/React.createElement(Group, {
144
+ }, themeProps), /*#__PURE__*/React.createElement(Group, {
139
145
  spacing: 0.5
140
- }, /*#__PURE__*/React.createElement(NavButton, {
146
+ }, /*#__PURE__*/React.createElement(NavButton, _extends({
141
147
  disabled: currentPage === 1,
142
148
  iconName: "general.leftChevron",
143
149
  onClick: onPageChange.bind(null, currentPage - 1),
144
150
  tooltip: {
145
151
  title: 'Previous Page'
146
152
  }
147
- }), /*#__PURE__*/React.createElement(NavButton, {
153
+ }, navButtonProps)), /*#__PURE__*/React.createElement(NavButton, _extends({
148
154
  disabled: currentPage === totalPages,
149
155
  iconName: "general.rightChevron",
150
156
  onClick: onPageChange.bind(null, currentPage + 1),
151
157
  tooltip: {
152
158
  title: 'Next Page'
153
159
  }
154
- })), renderPageLinks());
160
+ }, navButtonProps))), renderPageLinks());
155
161
  }
156
162
  }
@@ -12,7 +12,7 @@ import { merge } from 'lodash';
12
12
  import defaultTheme from '../system/default-theme';
13
13
  import { flattenPalette } from '../system';
14
14
  import { objectToCSSProperties, shallowEqual } from '../utils';
15
- import { setRootStyles, styleReset } from './styles';
15
+ import { getThemeDataAttribute, setRootStyles, styleReset } from './styles';
16
16
  var STORAGE_KEY = 'tapestry-react-theme';
17
17
  export var cache = createCache({
18
18
  key: 'tapestry-react'
@@ -52,6 +52,8 @@ function mergeThemes(a, b) {
52
52
  }
53
53
 
54
54
  export function ThemeProvider(_ref) {
55
+ var _ref2;
56
+
55
57
  var _ref$theme = _ref.theme,
56
58
  theme = _ref$theme === void 0 ? emptyTheme : _ref$theme,
57
59
  children = _ref.children;
@@ -64,7 +66,7 @@ export function ThemeProvider(_ref) {
64
66
 
65
67
  useLayoutEffect(function () {
66
68
  var nextTheme = mergeThemes(defaultTheme, theme);
67
- setRootStyles(objectToCSSProperties('colors', nextTheme.colors));
69
+ setRootStyles(nextTheme.id, objectToCSSProperties('colors', nextTheme.colors));
68
70
 
69
71
  if (!shallowEqual(mergedTheme, nextTheme)) {
70
72
  setMergedTheme(nextTheme);
@@ -74,7 +76,7 @@ export function ThemeProvider(_ref) {
74
76
  value: cache
75
77
  }, /*#__PURE__*/React.createElement(EmotionThemeProvider, {
76
78
  theme: mergedTheme
77
- }, children));
79
+ }, /*#__PURE__*/React.createElement("div", (_ref2 = {}, _ref2["" + getThemeDataAttribute(mergedTheme.id)] = true, _ref2), children)));
78
80
  }
79
81
  ThemeProvider.cache = cache;
80
82
  ThemeProvider.setRootStyles = setRootStyles;
@@ -1,29 +1,42 @@
1
1
  import { defaultTheme, flattenPalette } from '../system';
2
2
  import { objectToCSSProperties } from '../utils';
3
+ export function getThemeDataAttribute(themeId) {
4
+ if (themeId) {
5
+ return "data-tapestry-react-theme-provider-" + themeId;
6
+ } else {
7
+ return 'data-tapestry-react-theme-provider';
8
+ }
9
+ }
3
10
 
4
- var getRootStyles = function getRootStyles(styles) {
11
+ var getRootStyles = function getRootStyles(id, styles) {
5
12
  var styleString = Object.keys(styles).map(function (key) {
6
13
  return key + ": " + styles[key];
7
14
  }).join('; ');
8
- return ":root { " + styleString + " }";
15
+ return "[" + getThemeDataAttribute(id) + "] { " + styleString + " }";
9
16
  };
10
17
 
11
- export var setRootStyles = function setRootStyles(styles) {
12
- var styleElement = document.getElementById('tapestry-react-style');
18
+ export var setRootStyles = function setRootStyles(themeId, styles) {
19
+ ensureStyleElement(themeId);
20
+ var styleElement = document.getElementById("tapestry-react-style-" + themeId);
13
21
  var sheet = styleElement.sheet;
14
- var styleString = getRootStyles(styles);
22
+ var styleString = getRootStyles(themeId, styles);
15
23
  sheet.deleteRule(0);
16
24
  sheet.insertRule(styleString, 0);
17
25
  };
18
26
  export var defaultColorProperties = objectToCSSProperties('colors', flattenPalette(defaultTheme.colors));
19
- export var styleReset = ("\n" + getRootStyles(defaultColorProperties) + "\n\n.tapestry-react-reset {\n appearance: none;\n box-sizing: border-box;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';\n font-weight: 400;\n text-decoration: none;\n flex: 0 0 auto;\n min-width: 0px;\n min-height: 0px;\n padding: 0px;\n margin: 0px;\n border: 0px solid transparent;\n background-color: transparent;\n color: inherit;\n}\n\n.tapestry-react-reset::-moz-focus-inner {\n padding: 0px;\n border: 0px;\n}\n\n.tapestry-react-reset:focus:not(.focus-visible) {\n outline: 0px;\n}\n" // minify string
27
+ export var styleReset = ("\n" + getRootStyles(null, defaultColorProperties) + "\n\n.tapestry-react-reset {\n appearance: none;\n box-sizing: border-box;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';\n font-weight: 400;\n text-decoration: none;\n flex: 0 0 auto;\n min-width: 0px;\n min-height: 0px;\n padding: 0px;\n margin: 0px;\n border: 0px solid transparent;\n background-color: transparent;\n color: inherit;\n}\n\n.tapestry-react-reset::-moz-focus-inner {\n padding: 0px;\n border: 0px;\n}\n\n.tapestry-react-reset:focus:not(.focus-visible) {\n outline: 0px;\n}\n" // minify string
20
28
  ).replace(/\n/g, '').replace(/\s\s+/g, ' '); // we use our own global style implementation in place of Emotion Global
21
29
  // so we can have more control over when styles are injected since multiple
22
30
  // Providers can be used on a page
23
31
 
24
- if (typeof window !== 'undefined' && !document.getElementById('tapestry-react-style')) {
25
- var styleElement = document.createElement('style');
26
- styleElement.id = 'tapestry-react-style';
27
- styleElement.innerHTML = styleReset;
28
- document.head.insertAdjacentElement('afterbegin', styleElement);
32
+ function ensureStyleElement(themeId) {
33
+ // we use our own global style implementation in place of Emotion Global
34
+ // so we can have more control over when styles are injected since multiple
35
+ // Providers can be used on a page
36
+ if (typeof window !== 'undefined' && !document.getElementById("tapestry-react-style-" + themeId)) {
37
+ var styleElement = document.createElement('style');
38
+ styleElement.id = "tapestry-react-style-" + themeId;
39
+ styleElement.innerHTML = styleReset;
40
+ document.head.insertAdjacentElement('afterbegin', styleElement);
41
+ }
29
42
  }
@@ -1,5 +1,5 @@
1
- import * as general from "@planningcenter/icons/paths/general";
2
- import * as tapestry from "@planningcenter/icons/paths/tapestry";
1
+ import * as general from '@planningcenter/icons/paths/general';
2
+ import * as tapestry from '@planningcenter/icons/paths/tapestry';
3
3
  import { boxSizes } from './box-sizes';
4
4
  import { buttonThemes } from './button-themes';
5
5
  import { colors } from './colors';
@@ -11,6 +11,7 @@ var controlStyles = {
11
11
  checkedStroke: 'primary'
12
12
  };
13
13
  var defaultTheme = {
14
+ id: 'default',
14
15
  boxSizes: boxSizes,
15
16
  colors: colors,
16
17
  icons: {
@@ -2,15 +2,27 @@ export declare type PaginationProps = {
2
2
  /**
3
3
  * Change the color of the active page
4
4
  */
5
- activeColor: string;
5
+ activeColor?: string;
6
+ /**
7
+ * Accepts any valid [Button](/button) props.
8
+ */
9
+ activePageLinkProps?: object;
6
10
  /**
7
11
  * Current visible page number
8
12
  */
9
13
  currentPage: number;
14
+ /**
15
+ * Accepts any valid [Button](/button) props.
16
+ */
17
+ navButtonProps?: object;
10
18
  /**
11
19
  * Callback when new page is requested
12
20
  */
13
21
  onPageChange: (nextPage: number) => undefined;
22
+ /**
23
+ * Accepts any valid [Button](/button) props.
24
+ */
25
+ pageLinkProps?: object;
14
26
  /**
15
27
  * Total available pages
16
28
  */
@@ -20,4 +32,4 @@ export declare type PaginationProps = {
20
32
  */
21
33
  visiblePages?: number;
22
34
  };
23
- export default function Pagination({ activeColor, currentPage, onPageChange, visiblePages, totalPages, ...restProps }: PaginationProps): JSX.Element;
35
+ export default function Pagination({ currentPage, onPageChange, visiblePages, totalPages, ...restProps }: PaginationProps): JSX.Element;
@@ -13,7 +13,7 @@ export declare function ThemeProvider({ theme, children, }: {
13
13
  }): JSX.Element;
14
14
  export declare namespace ThemeProvider {
15
15
  var cache: import("@emotion/utils").EmotionCache;
16
- var setRootStyles: (styles: any) => void;
16
+ var setRootStyles: (themeId: any, styles: any) => void;
17
17
  var styleReset: string;
18
18
  var themeInitializerScript: string;
19
19
  var themeStorage: {
@@ -1,3 +1,4 @@
1
- export declare const setRootStyles: (styles: any) => void;
1
+ export declare function getThemeDataAttribute(themeId: any): string;
2
+ export declare const setRootStyles: (themeId: any, styles: any) => void;
2
3
  export declare const defaultColorProperties: any;
3
4
  export declare const styleReset: string;
@@ -184,6 +184,7 @@ export interface ButtonTheme {
184
184
  }
185
185
 
186
186
  export interface Theme {
187
+ id?: string
187
188
  boxSizes?: Record<keyof BoxSizes, BoxProps>
188
189
  breakpoints?: Partial<Breakpoints>
189
190
  button?: { themes?: { [key: string]: ButtonTheme } }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/tapestry-react",
3
- "version": "2.5.0",
3
+ "version": "2.6.0-rc.0",
4
4
  "description": "A collection of flexible React components to help you build resilient, accessible user interfaces quickly and effectively.",
5
5
  "author": "Front End Systems Engineering <frontend@pco.bz>",
6
6
  "main": "dist/cjs/index.js",
package/src/.DS_Store ADDED
Binary file
@@ -346,7 +346,7 @@ export function Button({
346
346
  (restProps as any).as &&
347
347
  (restProps as any).as !== "button"
348
348
  ) {
349
- throw Error(
349
+ console.log(
350
350
  `Tapestry-React: <Button/> type prop is only supported by <button> and not <${(restProps as any).as}>.`
351
351
  )
352
352
  }
@@ -120,23 +120,9 @@ function Checkbox({
120
120
  `Tapestry-React: <Checkbox/> must define a "label" prop or have a parent that renders a label for proper accessibility.`
121
121
  )
122
122
  useLayoutEffect(() => {
123
- function findParent(node, findMatch) {
124
- if (node && node !== document.documentElement) {
125
- const matchFound = findMatch(node.parentNode)
126
- if (matchFound) {
127
- return node.parentNode
128
- } else {
129
- return findParent(node.parentNode, findMatch)
130
- }
131
- } else {
132
- return null
133
- }
134
- }
135
123
  if (label === undefined) {
136
- const labelParent = findParent(
137
- ref.current,
138
- (parentNode) => parentNode.tagName === 'LABEL'
139
- )
124
+ const labelParent = ref.current.closest('label') !== null
125
+
140
126
  if (!labelParent) {
141
127
  setNeedsParentLabel(true)
142
128
  }
@@ -2,6 +2,7 @@
2
2
  title: Pagination
3
3
  category: General
4
4
  propsSummary: Accepts [StackView](/stackview) props.
5
+ themeKey: pagination
5
6
  ---
6
7
 
7
8
  ```jsx live
@@ -7,7 +7,7 @@ import StackView from '../StackView'
7
7
  import { range } from '../utils'
8
8
  import { parseColor } from '../system/utils'
9
9
  import { useWindowWidth } from '@react-hook/window-size'
10
- import { useThemeValue } from '../system'
10
+ import { useThemeValue, useThemeProps } from '../system'
11
11
 
12
12
  function getVisiblePages(currentPage, totalPages, visiblePages) {
13
13
  const start = Math.max(
@@ -40,18 +40,33 @@ export type PaginationProps = {
40
40
  /**
41
41
  * Change the color of the active page
42
42
  */
43
- activeColor: string
43
+ activeColor?: string
44
+
45
+ /**
46
+ * Accepts any valid [Button](/button) props.
47
+ */
48
+ activePageLinkProps?: object
44
49
 
45
50
  /**
46
51
  * Current visible page number
47
52
  */
48
53
  currentPage: number
49
54
 
55
+ /**
56
+ * Accepts any valid [Button](/button) props.
57
+ */
58
+ navButtonProps?: object
59
+
50
60
  /**
51
61
  * Callback when new page is requested
52
62
  */
53
63
  onPageChange: (nextPage: number) => undefined
54
64
 
65
+ /**
66
+ * Accepts any valid [Button](/button) props.
67
+ */
68
+ pageLinkProps?: object
69
+
55
70
  /**
56
71
  * Total available pages
57
72
  */
@@ -83,7 +98,6 @@ const NavButton = ({ disabled, iconName, ...props }) => {
83
98
  }
84
99
 
85
100
  export default function Pagination({
86
- activeColor = '#5b8bf7',
87
101
  currentPage,
88
102
  onPageChange = () => null,
89
103
  visiblePages,
@@ -91,6 +105,13 @@ export default function Pagination({
91
105
  ...restProps
92
106
  }: PaginationProps) {
93
107
  const { xs: xsBreakpoint } = useThemeValue('breakpoints')
108
+ const {
109
+ activeColor = '#5b8bf7',
110
+ navButtonProps,
111
+ pageLinkProps,
112
+ activePageLinkProps,
113
+ ...themeProps
114
+ } = useThemeProps('pagination', { ...restProps })
94
115
 
95
116
  const currentWidth = useWindowWidth()
96
117
 
@@ -123,7 +144,12 @@ export default function Pagination({
123
144
  square
124
145
  title={number}
125
146
  variant={isCurrentPage ? 'fill' : 'naked'}
126
- {...(isCurrentPage && { backgroundColor: activeColor, color: '#fff' })}
147
+ {...pageLinkProps}
148
+ {...(isCurrentPage && {
149
+ backgroundColor: activeColor,
150
+ color: '#fff',
151
+ ...activePageLinkProps,
152
+ })}
127
153
  />
128
154
  )
129
155
  }
@@ -150,7 +176,7 @@ export default function Pagination({
150
176
  shrink={0}
151
177
  spacing={0.5}
152
178
  width="100%"
153
- {...restProps}
179
+ {...themeProps}
154
180
  >
155
181
  <Group spacing={0.5}>
156
182
  <NavButton
@@ -158,12 +184,14 @@ export default function Pagination({
158
184
  iconName="general.leftChevron"
159
185
  onClick={onPageChange.bind(null, currentPage - 1)}
160
186
  tooltip={{ title: 'Previous Page' }}
187
+ {...navButtonProps}
161
188
  />
162
189
  <NavButton
163
190
  disabled={currentPage === totalPages}
164
191
  iconName="general.rightChevron"
165
192
  onClick={onPageChange.bind(null, currentPage + 1)}
166
193
  tooltip={{ title: 'Next Page' }}
194
+ {...navButtonProps}
167
195
  />
168
196
  </Group>
169
197
  {renderPageLinks()}
@@ -8,7 +8,7 @@ import defaultTheme from '../system/default-theme'
8
8
  import { flattenPalette } from '../system'
9
9
  import { Theme } from '../index'
10
10
  import { objectToCSSProperties, shallowEqual } from '../utils'
11
- import { setRootStyles, styleReset } from './styles'
11
+ import { getThemeDataAttribute, setRootStyles, styleReset } from './styles'
12
12
 
13
13
  const STORAGE_KEY = 'tapestry-react-theme'
14
14
 
@@ -65,7 +65,10 @@ export function ThemeProvider({
65
65
  )
66
66
  useLayoutEffect(() => {
67
67
  const nextTheme = mergeThemes(defaultTheme, theme)
68
- setRootStyles(objectToCSSProperties('colors', nextTheme.colors))
68
+ setRootStyles(
69
+ nextTheme.id,
70
+ objectToCSSProperties('colors', nextTheme.colors)
71
+ )
69
72
  if (!shallowEqual(mergedTheme, nextTheme)) {
70
73
  setMergedTheme(nextTheme)
71
74
  }
@@ -73,7 +76,9 @@ export function ThemeProvider({
73
76
  return (
74
77
  <CacheProvider value={cache}>
75
78
  <EmotionThemeProvider theme={mergedTheme}>
76
- {children}
79
+ <div {...{ [`${getThemeDataAttribute(mergedTheme.id)}`]: true }}>
80
+ {children}
81
+ </div>
77
82
  </EmotionThemeProvider>
78
83
  </CacheProvider>
79
84
  )
@@ -1,17 +1,30 @@
1
1
  import { defaultTheme, flattenPalette } from '../system'
2
2
  import { objectToCSSProperties } from '../utils'
3
3
 
4
- const getRootStyles = (styles) => {
4
+ export function getThemeDataAttribute(themeId) {
5
+ if (themeId) {
6
+ return `data-tapestry-react-theme-provider-${themeId}`
7
+ } else {
8
+ return 'data-tapestry-react-theme-provider'
9
+ }
10
+ }
11
+
12
+ const getRootStyles = (id, styles) => {
5
13
  const styleString = Object.keys(styles)
6
14
  .map((key) => `${key}: ${styles[key]}`)
7
15
  .join('; ')
8
- return `:root { ${styleString} }`
16
+
17
+ return `[${getThemeDataAttribute(id)}] { ${styleString} }`
9
18
  }
10
19
 
11
- export const setRootStyles = (styles) => {
12
- const styleElement = <HTMLStyleElement>document.getElementById('tapestry-react-style')
20
+ export const setRootStyles = (themeId, styles) => {
21
+ ensureStyleElement(themeId)
22
+ const styleElement = <HTMLStyleElement>(
23
+ document.getElementById(`tapestry-react-style-${themeId}`)
24
+ )
25
+
13
26
  const sheet = <CSSStyleSheet>styleElement.sheet
14
- const styleString = getRootStyles(styles)
27
+ const styleString = getRootStyles(themeId, styles)
15
28
  sheet.deleteRule(0)
16
29
  sheet.insertRule(styleString, 0)
17
30
  }
@@ -22,7 +35,7 @@ export const defaultColorProperties = objectToCSSProperties(
22
35
  )
23
36
 
24
37
  export const styleReset = `
25
- ${getRootStyles(defaultColorProperties)}
38
+ ${getRootStyles(null, defaultColorProperties)}
26
39
 
27
40
  .tapestry-react-reset {
28
41
  appearance: none;
@@ -56,9 +69,17 @@ ${getRootStyles(defaultColorProperties)}
56
69
  // we use our own global style implementation in place of Emotion Global
57
70
  // so we can have more control over when styles are injected since multiple
58
71
  // Providers can be used on a page
59
- if (typeof window !== 'undefined' && !document.getElementById('tapestry-react-style')) {
60
- const styleElement = document.createElement('style')
61
- styleElement.id = 'tapestry-react-style'
62
- styleElement.innerHTML = styleReset
63
- document.head.insertAdjacentElement('afterbegin', styleElement)
72
+ function ensureStyleElement(themeId) {
73
+ // we use our own global style implementation in place of Emotion Global
74
+ // so we can have more control over when styles are injected since multiple
75
+ // Providers can be used on a page
76
+ if (
77
+ typeof window !== 'undefined' &&
78
+ !document.getElementById(`tapestry-react-style-${themeId}`)
79
+ ) {
80
+ const styleElement = document.createElement('style')
81
+ styleElement.id = `tapestry-react-style-${themeId}`
82
+ styleElement.innerHTML = styleReset
83
+ document.head.insertAdjacentElement('afterbegin', styleElement)
84
+ }
64
85
  }
package/src/index.d.ts CHANGED
@@ -184,6 +184,7 @@ export interface ButtonTheme {
184
184
  }
185
185
 
186
186
  export interface Theme {
187
+ id?: string
187
188
  boxSizes?: Record<keyof BoxSizes, BoxProps>
188
189
  breakpoints?: Partial<Breakpoints>
189
190
  button?: { themes?: { [key: string]: ButtonTheme } }
@@ -1,5 +1,5 @@
1
- import * as general from "@planningcenter/icons/paths/general"
2
- import * as tapestry from "@planningcenter/icons/paths/tapestry"
1
+ import * as general from '@planningcenter/icons/paths/general'
2
+ import * as tapestry from '@planningcenter/icons/paths/tapestry'
3
3
 
4
4
  import { Theme } from '../index'
5
5
 
@@ -16,6 +16,7 @@ const controlStyles = {
16
16
  }
17
17
 
18
18
  const defaultTheme: Theme = {
19
+ id: 'default',
19
20
  boxSizes,
20
21
  colors,
21
22
  icons: {