@zendeskgarden/react-theming 9.0.0-next.20 → 9.0.0-next.21

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.
@@ -5,7 +5,7 @@
5
5
  * found at http://www.apache.org/licenses/LICENSE-2.0.
6
6
  */
7
7
  import { css, keyframes } from 'styled-components';
8
- import { stripUnit, math } from 'polished';
8
+ import { stripUnit } from 'polished';
9
9
 
10
10
  const animationStyles = (position, modifier) => {
11
11
  const property = position.split('-')[0];
@@ -13,33 +13,40 @@ const animationStyles = (position, modifier) => {
13
13
  return css(["&", "::before,&", "::after{animation:0.3s ease-in-out ", ";}"], modifier, modifier, animationName);
14
14
  };
15
15
  const positionStyles = (position, size, inset) => {
16
- const margin = math(`${size} / -2`);
17
- const placement = math(`${margin} + ${inset}`);
18
- let transform;
16
+ const defaultInset = 0.3;
17
+ const margin = size / -2;
18
+ const placement = Math.round((margin + inset + defaultInset) * 100) / 100;
19
+ const marginPx = `${margin}px`;
20
+ const placementPx = `${placement}px`;
21
+ const sizePx = `${size}px`;
19
22
  let positionCss;
23
+ let transform;
20
24
  if (position.startsWith('top')) {
21
25
  transform = 'rotate(-135deg)';
22
- positionCss = css(["top:", ";right:", ";left:", ";margin-left:", ";"], placement, position === 'top-right' && size, position === 'top' ? '50%' : position === 'top-left' && size, position === 'top' && margin);
26
+ positionCss = css(["top:", ";right:", ";left:", ";margin-left:", ";"], placementPx, position === 'top-right' && sizePx, position === 'top' ? '50%' : position === 'top-left' && sizePx, position === 'top' && marginPx);
23
27
  } else if (position.startsWith('right')) {
24
28
  transform = 'rotate(-45deg)';
25
- positionCss = css(["top:", ";right:", ";bottom:", ";margin-top:", ";"], position === 'right' ? '50%' : position === 'right-top' && size, placement, position === 'right-bottom' && size, position === 'right' && margin);
29
+ positionCss = css(["top:", ";right:", ";bottom:", ";margin-top:", ";"], position === 'right' ? '50%' : position === 'right-top' && sizePx, placementPx, position === 'right-bottom' && sizePx, position === 'right' && marginPx);
26
30
  } else if (position.startsWith('bottom')) {
27
31
  transform = 'rotate(45deg)';
28
- positionCss = css(["right:", ";bottom:", ";left:", ";margin-left:", ";"], position === 'bottom-right' && size, placement, position === 'bottom' ? '50%' : position === 'bottom-left' && size, position === 'bottom' && margin);
32
+ positionCss = css(["right:", ";bottom:", ";left:", ";margin-left:", ";"], position === 'bottom-right' && sizePx, placementPx, position === 'bottom' ? '50%' : position === 'bottom-left' && sizePx, position === 'bottom' && marginPx);
29
33
  } else if (position.startsWith('left')) {
30
34
  transform = 'rotate(135deg)';
31
- positionCss = css(["top:", ";bottom:", ";left:", ";margin-top:", ";"], position === 'left' ? '50%' : position === 'left-top' && size, size, placement, position === 'left' && margin);
35
+ positionCss = css(["top:", ";bottom:", ";left:", ";margin-top:", ";"], position === 'left' ? '50%' : position === 'left-top' && sizePx, size, placementPx, position === 'left' && marginPx);
32
36
  }
33
37
  return css(["&::before,&::after{transform:", ";", ";}"], transform, positionCss);
34
38
  };
35
39
  function arrowStyles(position) {
36
40
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
37
- const inset = options.inset || '0';
38
- const size = options.size === undefined ? 6 : stripUnit(options.size);
39
- const squareSize = `${Math.round(size * 2 / Math.sqrt(2))}px`;
41
+ const inset = stripUnit(options.inset || '0');
42
+ const size = stripUnit(options.size || '6');
43
+ const sizeOffset = 2;
44
+ const squareSize = size * 2 / Math.sqrt(2) + sizeOffset;
45
+ const squareSizeRounded = Math.round(squareSize * 100) / 100;
46
+ const squareSizePx = `${squareSizeRounded}px`;
40
47
  const afterOffset = 0;
41
48
  const beforeOffset = afterOffset + 2;
42
- return css(["position:relative;&::before,&::after{position:absolute;border-width:inherit;border-style:inherit;width:", ";height:", ";content:'';box-sizing:inherit;}&::before{border-color:inherit;background-color:transparent;clip-path:polygon(100% ", "px,", "px 100%,100% 100%);}&::after{border-color:transparent;background-clip:content-box;background-color:inherit;clip-path:polygon(100% ", "px,", "px 100%,100% 100%);}", ";", ";"], squareSize, squareSize, beforeOffset, beforeOffset, afterOffset, afterOffset, positionStyles(position, squareSize, inset), options.animationModifier && animationStyles(position, options.animationModifier));
49
+ return css(["position:relative;&::before,&::after{position:absolute;border-width:inherit;border-style:inherit;background-color:inherit;width:", ";height:", ";content:'';box-sizing:inherit;}&::before{border-color:inherit;clip-path:polygon(100% ", "px,", "px 100%,100% 100%);}&::after{border-color:transparent;background-clip:content-box;clip-path:polygon(100% ", "px,", "px 100%,100% 100%);}", ";", ";"], squareSizePx, squareSizePx, beforeOffset, beforeOffset, afterOffset, afterOffset, positionStyles(position, squareSizeRounded, inset), options.animationModifier && animationStyles(position, options.animationModifier));
43
50
  }
44
51
 
45
52
  export { arrowStyles as default };
package/dist/index.cjs.js CHANGED
@@ -1175,33 +1175,40 @@ const animationStyles$1 = (position, modifier) => {
1175
1175
  return styled.css(["&", "::before,&", "::after{animation:0.3s ease-in-out ", ";}"], modifier, modifier, animationName);
1176
1176
  };
1177
1177
  const positionStyles = (position, size, inset) => {
1178
- const margin = polished.math(`${size} / -2`);
1179
- const placement = polished.math(`${margin} + ${inset}`);
1180
- let transform;
1178
+ const defaultInset = 0.3;
1179
+ const margin = size / -2;
1180
+ const placement = Math.round((margin + inset + defaultInset) * 100) / 100;
1181
+ const marginPx = `${margin}px`;
1182
+ const placementPx = `${placement}px`;
1183
+ const sizePx = `${size}px`;
1181
1184
  let positionCss;
1185
+ let transform;
1182
1186
  if (position.startsWith('top')) {
1183
1187
  transform = 'rotate(-135deg)';
1184
- positionCss = styled.css(["top:", ";right:", ";left:", ";margin-left:", ";"], placement, position === 'top-right' && size, position === 'top' ? '50%' : position === 'top-left' && size, position === 'top' && margin);
1188
+ positionCss = styled.css(["top:", ";right:", ";left:", ";margin-left:", ";"], placementPx, position === 'top-right' && sizePx, position === 'top' ? '50%' : position === 'top-left' && sizePx, position === 'top' && marginPx);
1185
1189
  } else if (position.startsWith('right')) {
1186
1190
  transform = 'rotate(-45deg)';
1187
- positionCss = styled.css(["top:", ";right:", ";bottom:", ";margin-top:", ";"], position === 'right' ? '50%' : position === 'right-top' && size, placement, position === 'right-bottom' && size, position === 'right' && margin);
1191
+ positionCss = styled.css(["top:", ";right:", ";bottom:", ";margin-top:", ";"], position === 'right' ? '50%' : position === 'right-top' && sizePx, placementPx, position === 'right-bottom' && sizePx, position === 'right' && marginPx);
1188
1192
  } else if (position.startsWith('bottom')) {
1189
1193
  transform = 'rotate(45deg)';
1190
- positionCss = styled.css(["right:", ";bottom:", ";left:", ";margin-left:", ";"], position === 'bottom-right' && size, placement, position === 'bottom' ? '50%' : position === 'bottom-left' && size, position === 'bottom' && margin);
1194
+ positionCss = styled.css(["right:", ";bottom:", ";left:", ";margin-left:", ";"], position === 'bottom-right' && sizePx, placementPx, position === 'bottom' ? '50%' : position === 'bottom-left' && sizePx, position === 'bottom' && marginPx);
1191
1195
  } else if (position.startsWith('left')) {
1192
1196
  transform = 'rotate(135deg)';
1193
- positionCss = styled.css(["top:", ";bottom:", ";left:", ";margin-top:", ";"], position === 'left' ? '50%' : position === 'left-top' && size, size, placement, position === 'left' && margin);
1197
+ positionCss = styled.css(["top:", ";bottom:", ";left:", ";margin-top:", ";"], position === 'left' ? '50%' : position === 'left-top' && sizePx, size, placementPx, position === 'left' && marginPx);
1194
1198
  }
1195
1199
  return styled.css(["&::before,&::after{transform:", ";", ";}"], transform, positionCss);
1196
1200
  };
1197
1201
  function arrowStyles(position) {
1198
1202
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1199
- const inset = options.inset || '0';
1200
- const size = options.size === undefined ? 6 : polished.stripUnit(options.size);
1201
- const squareSize = `${Math.round(size * 2 / Math.sqrt(2))}px`;
1203
+ const inset = polished.stripUnit(options.inset || '0');
1204
+ const size = polished.stripUnit(options.size || '6');
1205
+ const sizeOffset = 2;
1206
+ const squareSize = size * 2 / Math.sqrt(2) + sizeOffset;
1207
+ const squareSizeRounded = Math.round(squareSize * 100) / 100;
1208
+ const squareSizePx = `${squareSizeRounded}px`;
1202
1209
  const afterOffset = 0;
1203
1210
  const beforeOffset = afterOffset + 2;
1204
- return styled.css(["position:relative;&::before,&::after{position:absolute;border-width:inherit;border-style:inherit;width:", ";height:", ";content:'';box-sizing:inherit;}&::before{border-color:inherit;background-color:transparent;clip-path:polygon(100% ", "px,", "px 100%,100% 100%);}&::after{border-color:transparent;background-clip:content-box;background-color:inherit;clip-path:polygon(100% ", "px,", "px 100%,100% 100%);}", ";", ";"], squareSize, squareSize, beforeOffset, beforeOffset, afterOffset, afterOffset, positionStyles(position, squareSize, inset), options.animationModifier && animationStyles$1(position, options.animationModifier));
1211
+ return styled.css(["position:relative;&::before,&::after{position:absolute;border-width:inherit;border-style:inherit;background-color:inherit;width:", ";height:", ";content:'';box-sizing:inherit;}&::before{border-color:inherit;clip-path:polygon(100% ", "px,", "px 100%,100% 100%);}&::after{border-color:transparent;background-clip:content-box;clip-path:polygon(100% ", "px,", "px 100%,100% 100%);}", ";", ";"], squareSizePx, squareSizePx, beforeOffset, beforeOffset, afterOffset, afterOffset, positionStyles(position, squareSizeRounded, inset), options.animationModifier && animationStyles$1(position, options.animationModifier));
1205
1212
  }
1206
1213
 
1207
1214
  const useDocument = theme => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendeskgarden/react-theming",
3
- "version": "9.0.0-next.20",
3
+ "version": "9.0.0-next.21",
4
4
  "description": "Theming utilities and components within the Garden Design System",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Zendesk Garden <garden@zendesk.com>",
@@ -47,5 +47,5 @@
47
47
  "access": "public"
48
48
  },
49
49
  "zendeskgarden:src": "src/index.ts",
50
- "gitHead": "eab087ac0d6e74b3a4489d37d067baf7a225e7a8"
50
+ "gitHead": "a245ce2b794ea65142174a6a1f855a111b2677a2"
51
51
  }