td-stylekit 27.3.1 → 28.0.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [28.0.0](https://github.com/treasure-data/td-stylekit/compare/v27.3.1...v28.0.0) (2022-09-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Don't expose Theme type externally ([#1337](https://github.com/treasure-data/td-stylekit/issues/1337)) ([65d64c0](https://github.com/treasure-data/td-stylekit/commit/65d64c0))
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * getLongestOptionLength no longer accepts Theme. Instead it accepts a style object with fontFamily as the only valid property.
12
+
1
13
  ## [27.3.1](https://github.com/treasure-data/td-stylekit/compare/v27.3.0...v27.3.1) (2022-09-26)
2
14
 
3
15
 
@@ -2,7 +2,10 @@ import type { StylesConfig } from 'react-select';
2
2
  import type { Theme } from '../ThemeProvider';
3
3
  import type { Options, OptionValue } from './components';
4
4
  import type { SelectComponentStyles } from './types';
5
- export declare function getLongestOptionLength(options: Options, theme: Theme, originalWidth?: number | string): string | number | undefined;
5
+ declare type TextWidthStyles = {
6
+ fontFamily: string;
7
+ };
8
+ export declare function getLongestOptionLength(options: Options, styles: TextWidthStyles, originalWidth?: number | string): string | number | undefined;
6
9
  declare type GetCustomStylesProps = {
7
10
  dataGrid?: boolean;
8
11
  guessMenuWidth?: boolean;
@@ -42,8 +42,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
42
42
  if (typeof window !== "undefined" && !window.gs) window.gs = function () {};
43
43
  if (typeof window !== "undefined" && !window.gsC) window.gsC = function () {};
44
44
 
45
- function getTextWidth(inputText, theme) {
46
- var font = "".concat(_elements.FONT_SIZE, "px ").concat(theme.fontFamily.body);
45
+ function getTextWidth(inputText, styles) {
46
+ var font = "".concat(_elements.FONT_SIZE, "px ").concat(styles.fontFamily);
47
47
  var canvas = document.createElement('canvas');
48
48
  var context = canvas.getContext('2d');
49
49
 
@@ -70,7 +70,7 @@ function byteLength(str) {
70
70
  return s;
71
71
  }
72
72
 
73
- function getLongestOptionLength(options, theme, originalWidth) {
73
+ function getLongestOptionLength(options, styles, originalWidth) {
74
74
  var maxObj = options.reduce(function (max, option, index) {
75
75
  var currSize = byteLength(option && option.label || '');
76
76
 
@@ -93,9 +93,9 @@ function getLongestOptionLength(options, theme, originalWidth) {
93
93
  var _option = options[maxObj.index];
94
94
 
95
95
  if (_typeof(_option) === 'object') {
96
- return getTextWidth(_option.label, theme);
96
+ return getTextWidth(_option.label, styles);
97
97
  } else {
98
- return getTextWidth(_option, theme);
98
+ return getTextWidth(String(_option), styles);
99
99
  }
100
100
  }
101
101
  }
@@ -177,7 +177,9 @@ function getMultiClearIndicatorStyle() {
177
177
 
178
178
  function getFixedWidthMenuStyle(theme, options, originalWidth) {
179
179
  return {
180
- width: "".concat(getLongestOptionLength(options, theme, originalWidth), "px")
180
+ width: "".concat(getLongestOptionLength(options, {
181
+ fontFamily: theme.fontFamily.body
182
+ }, originalWidth), "px")
181
183
  };
182
184
  }
183
185
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "td-stylekit",
3
- "version": "27.3.1",
3
+ "version": "28.0.0",
4
4
  "main": "dist/es/index.js",
5
5
  "module": "dist/es/index.js",
6
6
  "types": "dist/es/index.d.ts",