From 4824de6d75bc4cc80dfe3d012a8a15553cf1c0be Mon Sep 17 00:00:00 2001 From: David Hubler Date: Thu, 8 Nov 2018 10:13:24 -0800 Subject: [PATCH 1/4] Enumerating SHAPES and COLORS --- src/components/token/index.js | 1 + src/components/token/token.js | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/token/index.js b/src/components/token/index.js index ff55a40cc19..d41acb2d0cf 100644 --- a/src/components/token/index.js +++ b/src/components/token/index.js @@ -2,4 +2,5 @@ export { EuiToken, SIZES as TOKEN_SIZES, SHAPES as TOKEN_SHAPES, + COLORS as TOKEN_COLORS } from './token'; diff --git a/src/components/token/token.js b/src/components/token/token.js index b0fa4701b65..f1cc628907d 100644 --- a/src/components/token/token.js +++ b/src/components/token/token.js @@ -20,6 +20,23 @@ const shapeToClassMap = { export const SHAPES = Object.keys(shapeToClassMap); +const colorToClassMap = { + tokenTint01: 'eui--tokenTint01', + tokenTint02: 'eui--tokenTint02', + tokenTint03: 'eui--tokenTint03', + tokenTint04: 'eui--tokenTint04', + tokenTint05: 'eui--tokenTint05', + tokenTint06: 'eui--tokenTint06', + tokenTint07: 'eui--tokenTint07', + tokenTint08: 'eui--tokenTint08', + tokenTint09: 'eui--tokenTint09', + tokenTint10: 'eui--tokenTint10', + tokenTint11: 'eui--tokenTint11', + tokenTint12: 'eui--tokenTint12', +}; + +export const COLORS = Object.keys(colorToClassMap); + export const EuiToken = ({ iconType, displayOptions, @@ -89,8 +106,8 @@ EuiToken.propTypes = { * - `hideBorder`: disables the outer border */ displayOptions: PropTypes.shape({ - color: PropTypes.string, - shape: PropTypes.string, + color: PropTypes.oneOf(COLORS), + shape: PropTypes.oneOf(SHAPES), fill: PropTypes.boolean, hideBorder: PropTypes.boolean, }), From 12456224ee11c49bc8a1ab2141c2a73defbf1ecd Mon Sep 17 00:00:00 2001 From: David Hubler Date: Thu, 8 Nov 2018 10:26:15 -0800 Subject: [PATCH 2/4] Properly making use of the enumerated constants in classNames --- src/components/token/token.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/token/token.js b/src/components/token/token.js index f1cc628907d..59d270c1a4e 100644 --- a/src/components/token/token.js +++ b/src/components/token/token.js @@ -21,18 +21,18 @@ const shapeToClassMap = { export const SHAPES = Object.keys(shapeToClassMap); const colorToClassMap = { - tokenTint01: 'eui--tokenTint01', - tokenTint02: 'eui--tokenTint02', - tokenTint03: 'eui--tokenTint03', - tokenTint04: 'eui--tokenTint04', - tokenTint05: 'eui--tokenTint05', - tokenTint06: 'eui--tokenTint06', - tokenTint07: 'eui--tokenTint07', - tokenTint08: 'eui--tokenTint08', - tokenTint09: 'eui--tokenTint09', - tokenTint10: 'eui--tokenTint10', - tokenTint11: 'eui--tokenTint11', - tokenTint12: 'eui--tokenTint12', + tokenTint01: 'euiToken--tokenTint01', + tokenTint02: 'euiToken--tokenTint02', + tokenTint03: 'euiToken--tokenTint03', + tokenTint04: 'euiToken--tokenTint04', + tokenTint05: 'euiToken--tokenTint05', + tokenTint06: 'euiToken--tokenTint06', + tokenTint07: 'euiToken--tokenTint07', + tokenTint08: 'euiToken--tokenTint08', + tokenTint09: 'euiToken--tokenTint09', + tokenTint10: 'euiToken--tokenTint10', + tokenTint11: 'euiToken--tokenTint11', + tokenTint12: 'euiToken--tokenTint12', }; export const COLORS = Object.keys(colorToClassMap); @@ -69,8 +69,8 @@ export const EuiToken = ({ const classes = classNames( 'euiToken', - `euiToken--${tokenShape}`, - `euiToken--${tokenColor}`, + colorToClassMap[tokenColor], + shapeToClassMap[tokenShape], sizeToClassMap[size], { 'euiToken--fill': fill, From 15c1552cc29f3361e693bd692c1b6b109dcfcb83 Mon Sep 17 00:00:00 2001 From: David Hubler Date: Thu, 8 Nov 2018 12:25:18 -0800 Subject: [PATCH 3/4] Updating the changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaf4206f85f..77d56449d42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [`master`](https://github.com/elastic/eui/tree/master) +- `EuiToken` now exports enumerated constants for `SHAPES` and `COLORS` ([#1301](https://github.com/elastic/eui/pull/1301)) + No public interface changes since `5.0.1`. ## [`5.0.1`](https://github.com/elastic/eui/tree/v5.0.1) From b6838a81d806b061f68356f6da6155d4971bde2f Mon Sep 17 00:00:00 2001 From: Chandler Prall Date: Thu, 8 Nov 2018 16:33:36 -0700 Subject: [PATCH 4/4] updated snapshots --- .../token/__snapshots__/token.test.js.snap | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/components/token/__snapshots__/token.test.js.snap b/src/components/token/__snapshots__/token.test.js.snap index b055af8f74e..6e08a2ba52b 100644 --- a/src/components/token/__snapshots__/token.test.js.snap +++ b/src/components/token/__snapshots__/token.test.js.snap @@ -2,7 +2,7 @@ exports[`EuiToken is rendered 1`] = `