@vitality-ds/components 4.9.4 → 4.10.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.
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AVAILABLE_COLOR_VARIANTS = void 0;
7
+ // eslint-disable-next-line import/prefer-default-export
8
+ var AVAILABLE_COLOR_VARIANTS = exports.AVAILABLE_COLOR_VARIANTS = ["inherit", "hiContrast", "primary", "lowContrast", "disabled", "accent", "info", "moderate", "critical", "warning", "success"];
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _react = require("react");
8
+ var _colors = require("../constants/colors");
9
+ var _logic = require("../logic");
10
+ var useTypographyColors = function useTypographyColors(colorString) {
11
+ var result = (0, _react.useMemo)(function () {
12
+ return (0, _logic.isColorVariantValue)(colorString, _colors.AVAILABLE_COLOR_VARIANTS);
13
+ }, [colorString, _colors.AVAILABLE_COLOR_VARIANTS]);
14
+ return result;
15
+ };
16
+ var _default = exports["default"] = useTypographyColors;
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _react = require("react");
8
- var _constants = require("../constants");
8
+ var _variants = require("../constants/variants");
9
9
  var _logic = require("../logic");
10
10
  var useTypographyElementFromTagProp = function useTypographyElementFromTagProp(htmlTag, variant) {
11
11
  var renderedComponent = (0, _react.useMemo)(function () {
12
- return (0, _logic.getHtmlElementFromHtmlTagProp)(_constants.DEFAULT_VARIANT_ELEMENTS, htmlTag, variant);
12
+ return (0, _logic.getHtmlElementFromHtmlTagProp)(_variants.DEFAULT_VARIANT_ELEMENTS, htmlTag, variant);
13
13
  }, [htmlTag, variant]);
14
14
  return renderedComponent;
15
15
  };
@@ -8,6 +8,7 @@ exports["default"] = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
10
  var _react = _interopRequireDefault(require("react"));
11
+ var _useTypographyColors = _interopRequireDefault(require("./hooks/useTypographyColors"));
11
12
  var _useTypographyElementFromTagProp = _interopRequireDefault(require("./hooks/useTypographyElementFromTagProp"));
12
13
  var _styled = require("./styled");
13
14
  var _excluded = ["className", "style", "as", "css", "htmlTag", "variant", "color", "textAlign"];
@@ -24,11 +25,11 @@ function Typography(_ref) {
24
25
  textAlign = _ref.textAlign,
25
26
  rest = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
26
27
  var renderedComponent = (0, _useTypographyElementFromTagProp["default"])(htmlTag, variant);
28
+ var colorProps = (0, _useTypographyColors["default"])(color);
27
29
  return /*#__PURE__*/_react["default"].createElement(_styled.BaseTypography, (0, _extends2["default"])({}, rest, {
28
30
  as: renderedComponent,
29
- color: color,
30
31
  variant: variant,
31
32
  textAlign: textAlign
32
- }));
33
+ }, colorProps));
33
34
  }
34
35
  var _default = exports["default"] = Typography;
@@ -3,9 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getHtmlElementFromHtmlTagProp = void 0;
6
+ exports.isColorVariantValue = exports.getHtmlElementFromHtmlTagProp = void 0;
7
7
  // eslint-disable-next-line import/prefer-default-export
8
8
  var getHtmlElementFromHtmlTagProp = exports.getHtmlElementFromHtmlTagProp = function getHtmlElementFromHtmlTagProp(options, htmlTag, variant) {
9
9
  var variantKey = variant;
10
10
  return htmlTag || options[variantKey];
11
+ };
12
+ var isVariantValue = function isVariantValue(value, availableVariants) {
13
+ return availableVariants.includes(value);
14
+ };
15
+ var isColorVariantValue = exports.isColorVariantValue = function isColorVariantValue(value, availableVariants) {
16
+ if (isVariantValue(value, availableVariants)) {
17
+ return {
18
+ color: value
19
+ };
20
+ }
21
+ return {
22
+ css: {
23
+ color: value
24
+ }
25
+ };
11
26
  };
@@ -1,14 +1,29 @@
1
1
  "use strict";
2
2
 
3
- var _constants = require("./constants");
3
+ var _colors = require("./constants/colors");
4
+ var _variants = require("./constants/variants");
4
5
  var _logic = require("./logic");
5
6
  describe("getHtmlElementFromHtmlTagProp", function () {
6
7
  it("should return the htmlTag tag if it is provided to the function", function () {
7
- var tag = (0, _logic.getHtmlElementFromHtmlTagProp)(_constants.DEFAULT_VARIANT_ELEMENTS, "p", "pageTitle");
8
+ var tag = (0, _logic.getHtmlElementFromHtmlTagProp)(_variants.DEFAULT_VARIANT_ELEMENTS, "p", "pageTitle");
8
9
  expect(tag).toEqual("p");
9
10
  });
10
11
  it("should return the default tag if it is provided to the htmlTag parameter", function () {
11
- var tag = (0, _logic.getHtmlElementFromHtmlTagProp)(_constants.DEFAULT_VARIANT_ELEMENTS, null, "pageTitle");
12
- expect(tag).toEqual(_constants.DEFAULT_VARIANT_ELEMENTS.pageTitle);
12
+ var tag = (0, _logic.getHtmlElementFromHtmlTagProp)(_variants.DEFAULT_VARIANT_ELEMENTS, null, "pageTitle");
13
+ expect(tag).toEqual(_variants.DEFAULT_VARIANT_ELEMENTS.pageTitle);
14
+ });
15
+ it("should return the color prop and variant when passed a valid color variant", function () {
16
+ var colorProp = (0, _logic.isColorVariantValue)("hiContrast", _colors.AVAILABLE_COLOR_VARIANTS);
17
+ expect(colorProp).toEqual({
18
+ color: "hiContrast"
19
+ });
20
+ });
21
+ it("should return the css prop and color value when passed a value from the getColorScaleValueByUseCase() function", function () {
22
+ var colorProp = (0, _logic.isColorVariantValue)("$colors$warning9", _colors.AVAILABLE_COLOR_VARIANTS);
23
+ expect(colorProp).toEqual({
24
+ css: {
25
+ color: "$colors$warning9"
26
+ }
27
+ });
13
28
  });
14
29
  });
@@ -10,7 +10,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
11
  var _icons = require("@vitality-ds/icons");
12
12
  var _system = require("@vitality-ds/system");
13
- var _constants = require("../constants");
13
+ var _variants = require("../constants/variants");
14
14
  var _helpers = require("./helpers");
15
15
  var text = _system.colorUseCases.text;
16
16
  var overflowSharedStyles = {
@@ -145,7 +145,7 @@ var _default = exports["default"] = (0, _system.css)((0, _defineProperty2["defau
145
145
  2: (0, _helpers.getMaxLines)(2, "$body"),
146
146
  3: (0, _helpers.getMaxLines)(3, "$body")
147
147
  }
148
- }), "compoundVariants", (0, _toConsumableArray2["default"])((0, _helpers.getMaxLinesVariants)(_constants.AVAILABLE_MAX_LINES, _constants.AVAILABLE_VARIANTS))), "ul, ol", {
148
+ }), "compoundVariants", (0, _toConsumableArray2["default"])((0, _helpers.getMaxLinesVariants)(_variants.AVAILABLE_MAX_LINES, _variants.AVAILABLE_VARIANTS))), "ul, ol", {
149
149
  listStylePosition: "inside",
150
150
  paddingInlineStart: 0,
151
151
  marginBlock: "inherit"
@@ -0,0 +1,2 @@
1
+ import { AvailableColorVariants } from "../types";
2
+ export declare const AVAILABLE_COLOR_VARIANTS: AvailableColorVariants[];
@@ -0,0 +1,18 @@
1
+ import { ColorType } from "../types";
2
+ declare const useTypographyColors: (colorString: ColorType) => {
3
+ color: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate" | ({
4
+ "@bp1"?: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
5
+ "@bp2"?: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
6
+ "@bp3"?: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
7
+ "@initial"?: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
8
+ } & {
9
+ [x: string]: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
10
+ });
11
+ css?: undefined;
12
+ } | {
13
+ css: {
14
+ color: "$colors$blue2" | "$colors$cyan2" | "$colors$green2" | "$colors$grey2" | "$colors$greyA2" | "$colors$orange2" | "$colors$pink2" | "$colors$red2" | "$colors$violet2" | "$colors$yellow2" | "$colors$blue1" | "$colors$cyan1" | "$colors$green1" | "$colors$grey1" | "$colors$greyA1" | "$colors$orange1" | "$colors$pink1" | "$colors$red1" | "$colors$violet1" | "$colors$yellow1" | "$colors$blue7" | "$colors$cyan7" | "$colors$green7" | "$colors$grey7" | "$colors$greyA7" | "$colors$orange7" | "$colors$pink7" | "$colors$red7" | "$colors$violet7" | "$colors$yellow7" | "$colors$blue12" | "$colors$cyan12" | "$colors$green12" | "$colors$grey12" | "$colors$greyA12" | "$colors$orange12" | "$colors$pink12" | "$colors$red12" | "$colors$violet12" | "$colors$yellow12" | "$colors$blue3" | "$colors$cyan3" | "$colors$green3" | "$colors$grey3" | "$colors$greyA3" | "$colors$orange3" | "$colors$pink3" | "$colors$red3" | "$colors$violet3" | "$colors$yellow3" | "$colors$blue4" | "$colors$cyan4" | "$colors$green4" | "$colors$grey4" | "$colors$greyA4" | "$colors$orange4" | "$colors$pink4" | "$colors$red4" | "$colors$violet4" | "$colors$yellow4" | "$colors$blue5" | "$colors$cyan5" | "$colors$green5" | "$colors$grey5" | "$colors$greyA5" | "$colors$orange5" | "$colors$pink5" | "$colors$red5" | "$colors$violet5" | "$colors$yellow5" | "$colors$blue10" | "$colors$cyan10" | "$colors$green10" | "$colors$grey10" | "$colors$greyA10" | "$colors$orange10" | "$colors$pink10" | "$colors$red10" | "$colors$violet10" | "$colors$yellow10" | "$colors$blue9" | "$colors$cyan9" | "$colors$green9" | "$colors$grey9" | "$colors$greyA9" | "$colors$orange9" | "$colors$pink9" | "$colors$red9" | "$colors$violet9" | "$colors$yellow9" | "$colors$blue11" | "$colors$cyan11" | "$colors$green11" | "$colors$grey11" | "$colors$greyA11" | "$colors$orange11" | "$colors$pink11" | "$colors$red11" | "$colors$violet11" | "$colors$yellow11" | "$colors$blue6" | "$colors$cyan6" | "$colors$green6" | "$colors$grey6" | "$colors$greyA6" | "$colors$orange6" | "$colors$pink6" | "$colors$red6" | "$colors$violet6" | "$colors$yellow6" | "$colors$blue8" | "$colors$cyan8" | "$colors$green8" | "$colors$grey8" | "$colors$greyA8" | "$colors$orange8" | "$colors$pink8" | "$colors$red8" | "$colors$violet8" | "$colors$yellow8" | "$colors$blue13" | "$colors$cyan13" | "$colors$green13" | "$colors$grey13" | "$colors$greyA13" | "$colors$orange13" | "$colors$pink13" | "$colors$red13" | "$colors$violet13" | "$colors$yellow13" | "$colors$neutral2" | "$colors$neutralA2" | "$colors$primary2" | "$colors$accent2" | "$colors$success2" | "$colors$info2" | "$colors$warning2" | "$colors$critical2" | "$colors$brand2" | "$colors$neutral1" | "$colors$neutralA1" | "$colors$primary1" | "$colors$accent1" | "$colors$success1" | "$colors$info1" | "$colors$warning1" | "$colors$critical1" | "$colors$brand1" | "$colors$neutral7" | "$colors$neutralA7" | "$colors$primary7" | "$colors$accent7" | "$colors$success7" | "$colors$info7" | "$colors$warning7" | "$colors$critical7" | "$colors$brand7" | "$colors$neutral12" | "$colors$neutralA12" | "$colors$primary12" | "$colors$accent12" | "$colors$success12" | "$colors$info12" | "$colors$warning12" | "$colors$critical12" | "$colors$brand12" | "$colors$neutral3" | "$colors$neutralA3" | "$colors$primary3" | "$colors$accent3" | "$colors$success3" | "$colors$info3" | "$colors$warning3" | "$colors$critical3" | "$colors$brand3" | "$colors$neutral4" | "$colors$neutralA4" | "$colors$primary4" | "$colors$accent4" | "$colors$success4" | "$colors$info4" | "$colors$warning4" | "$colors$critical4" | "$colors$brand4" | "$colors$neutral5" | "$colors$neutralA5" | "$colors$primary5" | "$colors$accent5" | "$colors$success5" | "$colors$info5" | "$colors$warning5" | "$colors$critical5" | "$colors$brand5" | "$colors$neutral10" | "$colors$neutralA10" | "$colors$primary10" | "$colors$accent10" | "$colors$success10" | "$colors$info10" | "$colors$warning10" | "$colors$critical10" | "$colors$brand10" | "$colors$neutral9" | "$colors$neutralA9" | "$colors$primary9" | "$colors$accent9" | "$colors$success9" | "$colors$info9" | "$colors$warning9" | "$colors$critical9" | "$colors$brand9" | "$colors$neutral11" | "$colors$neutralA11" | "$colors$primary11" | "$colors$accent11" | "$colors$success11" | "$colors$info11" | "$colors$warning11" | "$colors$critical11" | "$colors$brand11" | "$colors$neutral6" | "$colors$neutralA6" | "$colors$primary6" | "$colors$accent6" | "$colors$success6" | "$colors$info6" | "$colors$warning6" | "$colors$critical6" | "$colors$brand6" | "$colors$neutral8" | "$colors$neutralA8" | "$colors$primary8" | "$colors$accent8" | "$colors$success8" | "$colors$info8" | "$colors$warning8" | "$colors$critical8" | "$colors$brand8" | "$colors$neutral13" | "$colors$neutralA13" | "$colors$primary13" | "$colors$accent13" | "$colors$success13" | "$colors$info13" | "$colors$warning13" | "$colors$critical13" | "$colors$brand13";
15
+ };
16
+ color?: undefined;
17
+ };
18
+ export default useTypographyColors;
@@ -1,3 +1,19 @@
1
- import { DEFAULT_VARIANT_ELEMENTS } from "./constants";
2
- import { AllowedTypographyHTMLElements, TypographyVariantOptions } from "./types";
1
+ import { DEFAULT_VARIANT_ELEMENTS } from "./constants/variants";
2
+ import { AllowedTypographyHTMLElements, AvailableColorVariants, ColorType, TypographyVariantOptions } from "./types";
3
3
  export declare const getHtmlElementFromHtmlTagProp: (options: typeof DEFAULT_VARIANT_ELEMENTS, htmlTag: AllowedTypographyHTMLElements, variant: TypographyVariantOptions) => AllowedTypographyHTMLElements;
4
+ export declare const isColorVariantValue: (value: ColorType, availableVariants: AvailableColorVariants[]) => {
5
+ color: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate" | ({
6
+ "@bp1"?: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
7
+ "@bp2"?: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
8
+ "@bp3"?: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
9
+ "@initial"?: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
10
+ } & {
11
+ [x: string]: "primary" | "accent" | "success" | "info" | "warning" | "critical" | "hiContrast" | "lowContrast" | "disabled" | "inherit" | "moderate";
12
+ });
13
+ css?: undefined;
14
+ } | {
15
+ css: {
16
+ color: "$colors$blue2" | "$colors$cyan2" | "$colors$green2" | "$colors$grey2" | "$colors$greyA2" | "$colors$orange2" | "$colors$pink2" | "$colors$red2" | "$colors$violet2" | "$colors$yellow2" | "$colors$blue1" | "$colors$cyan1" | "$colors$green1" | "$colors$grey1" | "$colors$greyA1" | "$colors$orange1" | "$colors$pink1" | "$colors$red1" | "$colors$violet1" | "$colors$yellow1" | "$colors$blue7" | "$colors$cyan7" | "$colors$green7" | "$colors$grey7" | "$colors$greyA7" | "$colors$orange7" | "$colors$pink7" | "$colors$red7" | "$colors$violet7" | "$colors$yellow7" | "$colors$blue12" | "$colors$cyan12" | "$colors$green12" | "$colors$grey12" | "$colors$greyA12" | "$colors$orange12" | "$colors$pink12" | "$colors$red12" | "$colors$violet12" | "$colors$yellow12" | "$colors$blue3" | "$colors$cyan3" | "$colors$green3" | "$colors$grey3" | "$colors$greyA3" | "$colors$orange3" | "$colors$pink3" | "$colors$red3" | "$colors$violet3" | "$colors$yellow3" | "$colors$blue4" | "$colors$cyan4" | "$colors$green4" | "$colors$grey4" | "$colors$greyA4" | "$colors$orange4" | "$colors$pink4" | "$colors$red4" | "$colors$violet4" | "$colors$yellow4" | "$colors$blue5" | "$colors$cyan5" | "$colors$green5" | "$colors$grey5" | "$colors$greyA5" | "$colors$orange5" | "$colors$pink5" | "$colors$red5" | "$colors$violet5" | "$colors$yellow5" | "$colors$blue10" | "$colors$cyan10" | "$colors$green10" | "$colors$grey10" | "$colors$greyA10" | "$colors$orange10" | "$colors$pink10" | "$colors$red10" | "$colors$violet10" | "$colors$yellow10" | "$colors$blue9" | "$colors$cyan9" | "$colors$green9" | "$colors$grey9" | "$colors$greyA9" | "$colors$orange9" | "$colors$pink9" | "$colors$red9" | "$colors$violet9" | "$colors$yellow9" | "$colors$blue11" | "$colors$cyan11" | "$colors$green11" | "$colors$grey11" | "$colors$greyA11" | "$colors$orange11" | "$colors$pink11" | "$colors$red11" | "$colors$violet11" | "$colors$yellow11" | "$colors$blue6" | "$colors$cyan6" | "$colors$green6" | "$colors$grey6" | "$colors$greyA6" | "$colors$orange6" | "$colors$pink6" | "$colors$red6" | "$colors$violet6" | "$colors$yellow6" | "$colors$blue8" | "$colors$cyan8" | "$colors$green8" | "$colors$grey8" | "$colors$greyA8" | "$colors$orange8" | "$colors$pink8" | "$colors$red8" | "$colors$violet8" | "$colors$yellow8" | "$colors$blue13" | "$colors$cyan13" | "$colors$green13" | "$colors$grey13" | "$colors$greyA13" | "$colors$orange13" | "$colors$pink13" | "$colors$red13" | "$colors$violet13" | "$colors$yellow13" | "$colors$neutral2" | "$colors$neutralA2" | "$colors$primary2" | "$colors$accent2" | "$colors$success2" | "$colors$info2" | "$colors$warning2" | "$colors$critical2" | "$colors$brand2" | "$colors$neutral1" | "$colors$neutralA1" | "$colors$primary1" | "$colors$accent1" | "$colors$success1" | "$colors$info1" | "$colors$warning1" | "$colors$critical1" | "$colors$brand1" | "$colors$neutral7" | "$colors$neutralA7" | "$colors$primary7" | "$colors$accent7" | "$colors$success7" | "$colors$info7" | "$colors$warning7" | "$colors$critical7" | "$colors$brand7" | "$colors$neutral12" | "$colors$neutralA12" | "$colors$primary12" | "$colors$accent12" | "$colors$success12" | "$colors$info12" | "$colors$warning12" | "$colors$critical12" | "$colors$brand12" | "$colors$neutral3" | "$colors$neutralA3" | "$colors$primary3" | "$colors$accent3" | "$colors$success3" | "$colors$info3" | "$colors$warning3" | "$colors$critical3" | "$colors$brand3" | "$colors$neutral4" | "$colors$neutralA4" | "$colors$primary4" | "$colors$accent4" | "$colors$success4" | "$colors$info4" | "$colors$warning4" | "$colors$critical4" | "$colors$brand4" | "$colors$neutral5" | "$colors$neutralA5" | "$colors$primary5" | "$colors$accent5" | "$colors$success5" | "$colors$info5" | "$colors$warning5" | "$colors$critical5" | "$colors$brand5" | "$colors$neutral10" | "$colors$neutralA10" | "$colors$primary10" | "$colors$accent10" | "$colors$success10" | "$colors$info10" | "$colors$warning10" | "$colors$critical10" | "$colors$brand10" | "$colors$neutral9" | "$colors$neutralA9" | "$colors$primary9" | "$colors$accent9" | "$colors$success9" | "$colors$info9" | "$colors$warning9" | "$colors$critical9" | "$colors$brand9" | "$colors$neutral11" | "$colors$neutralA11" | "$colors$primary11" | "$colors$accent11" | "$colors$success11" | "$colors$info11" | "$colors$warning11" | "$colors$critical11" | "$colors$brand11" | "$colors$neutral6" | "$colors$neutralA6" | "$colors$primary6" | "$colors$accent6" | "$colors$success6" | "$colors$info6" | "$colors$warning6" | "$colors$critical6" | "$colors$brand6" | "$colors$neutral8" | "$colors$neutralA8" | "$colors$primary8" | "$colors$accent8" | "$colors$success8" | "$colors$info8" | "$colors$warning8" | "$colors$critical8" | "$colors$brand8" | "$colors$neutral13" | "$colors$neutralA13" | "$colors$primary13" | "$colors$accent13" | "$colors$success13" | "$colors$info13" | "$colors$warning13" | "$colors$critical13" | "$colors$brand13";
17
+ };
18
+ color?: undefined;
19
+ };
@@ -1,5 +1,5 @@
1
1
  import { ScaleValue } from "@vitality-ds/system";
2
- import { AVAILABLE_VARIANTS } from "../constants";
2
+ import { AVAILABLE_VARIANTS } from "../constants/variants";
3
3
  export declare const getVariantStyles: (key: ScaleValue<"fontSizes"> | "inherit") => {
4
4
  fontSize: "inherit" | "$display100" | "$display200" | "$display300" | "$display400" | "$display500" | "$display600" | "$display700" | "$display800" | "$display900" | "$body" | "$caption" | "$pageTitle" | "$sectionTitle" | "$sectionSubtitle" | "$button" | "$textInput";
5
5
  fontWeight: "inherit" | "$display100" | "$display200" | "$display300" | "$display400" | "$display500" | "$display600" | "$display700" | "$display800" | "$display900" | "$body" | "$caption" | "$pageTitle" | "$sectionTitle" | "$sectionSubtitle" | "$button" | "$textInput";
@@ -1,12 +1,19 @@
1
1
  /// <reference types="react" />
2
- import { ComponentProps, ExcludedProps, VariantProps } from "@vitality-ds/system";
2
+ import { ComponentProps, ExcludedProps, ScaleValue, VariantProps } from "@vitality-ds/system";
3
3
  import type { valueof } from "../helpers/logic/type-helpers";
4
4
  import { BaseTypography } from "./styled";
5
5
  export declare type AllowedTypographyHTMLElements = keyof Pick<JSX.IntrinsicElements, "caption" | "small" | "span" | "div" | "p" | "h6" | "h5" | "h4" | "h3" | "h2" | "h1">;
6
- export declare type TypographyProps = ExcludedProps & ComponentProps<typeof BaseTypography> & {
6
+ export declare type AvailableColorVariants = VariantProps<typeof BaseTypography>["color"];
7
+ export declare type ColorScaleValues = `$colors${ScaleValue<"colors">}`;
8
+ export declare type ColorType = ColorScaleValues | AvailableColorVariants;
9
+ export declare type TypographyProps = ExcludedProps & Omit<ComponentProps<typeof BaseTypography>, "color"> & {
7
10
  /**
8
11
  * Override the rendered HTML element one of a predefined set of options
9
12
  */
10
13
  htmlTag?: AllowedTypographyHTMLElements;
14
+ /**
15
+ * Accepts any valid colour returned by getColorScaleValueByUseCase() or a pre-set list of legacy color names
16
+ */
17
+ color?: ColorType;
11
18
  };
12
19
  export declare type TypographyVariantOptions = valueof<Pick<VariantProps<typeof BaseTypography>, "variant">>;
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export var AVAILABLE_COLOR_VARIANTS = ["inherit", "hiContrast", "primary", "lowContrast", "disabled", "accent", "info", "moderate", "critical", "warning", "success"];
@@ -0,0 +1,10 @@
1
+ import { useMemo } from "react";
2
+ import { AVAILABLE_COLOR_VARIANTS } from "../constants/colors";
3
+ import { isColorVariantValue } from "../logic";
4
+ var useTypographyColors = function useTypographyColors(colorString) {
5
+ var result = useMemo(function () {
6
+ return isColorVariantValue(colorString, AVAILABLE_COLOR_VARIANTS);
7
+ }, [colorString, AVAILABLE_COLOR_VARIANTS]);
8
+ return result;
9
+ };
10
+ export default useTypographyColors;
@@ -1,5 +1,5 @@
1
1
  import { useMemo } from "react";
2
- import { DEFAULT_VARIANT_ELEMENTS } from "../constants";
2
+ import { DEFAULT_VARIANT_ELEMENTS } from "../constants/variants";
3
3
  import { getHtmlElementFromHtmlTagProp } from "../logic";
4
4
  var useTypographyElementFromTagProp = function useTypographyElementFromTagProp(htmlTag, variant) {
5
5
  var renderedComponent = useMemo(function () {
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["className", "style", "as", "css", "htmlTag", "variant", "color", "textAlign"];
4
4
  import React from "react";
5
+ import useTypographyColors from "./hooks/useTypographyColors";
5
6
  import useTypographyElementFromTagProp from "./hooks/useTypographyElementFromTagProp";
6
7
  import { BaseTypography } from "./styled";
7
8
  function Typography(_ref) {
@@ -17,11 +18,11 @@ function Typography(_ref) {
17
18
  textAlign = _ref.textAlign,
18
19
  rest = _objectWithoutProperties(_ref, _excluded);
19
20
  var renderedComponent = useTypographyElementFromTagProp(htmlTag, variant);
21
+ var colorProps = useTypographyColors(color);
20
22
  return /*#__PURE__*/React.createElement(BaseTypography, _extends({}, rest, {
21
23
  as: renderedComponent,
22
- color: color,
23
24
  variant: variant,
24
25
  textAlign: textAlign
25
- }));
26
+ }, colorProps));
26
27
  }
27
28
  export default Typography;
@@ -2,4 +2,19 @@
2
2
  export var getHtmlElementFromHtmlTagProp = function getHtmlElementFromHtmlTagProp(options, htmlTag, variant) {
3
3
  var variantKey = variant;
4
4
  return htmlTag || options[variantKey];
5
+ };
6
+ var isVariantValue = function isVariantValue(value, availableVariants) {
7
+ return availableVariants.includes(value);
8
+ };
9
+ export var isColorVariantValue = function isColorVariantValue(value, availableVariants) {
10
+ if (isVariantValue(value, availableVariants)) {
11
+ return {
12
+ color: value
13
+ };
14
+ }
15
+ return {
16
+ css: {
17
+ color: value
18
+ }
19
+ };
5
20
  };
@@ -1,5 +1,6 @@
1
- import { DEFAULT_VARIANT_ELEMENTS } from "./constants";
2
- import { getHtmlElementFromHtmlTagProp } from "./logic";
1
+ import { AVAILABLE_COLOR_VARIANTS } from "./constants/colors";
2
+ import { DEFAULT_VARIANT_ELEMENTS } from "./constants/variants";
3
+ import { getHtmlElementFromHtmlTagProp, isColorVariantValue } from "./logic";
3
4
  describe("getHtmlElementFromHtmlTagProp", function () {
4
5
  it("should return the htmlTag tag if it is provided to the function", function () {
5
6
  var tag = getHtmlElementFromHtmlTagProp(DEFAULT_VARIANT_ELEMENTS, "p", "pageTitle");
@@ -9,4 +10,18 @@ describe("getHtmlElementFromHtmlTagProp", function () {
9
10
  var tag = getHtmlElementFromHtmlTagProp(DEFAULT_VARIANT_ELEMENTS, null, "pageTitle");
10
11
  expect(tag).toEqual(DEFAULT_VARIANT_ELEMENTS.pageTitle);
11
12
  });
13
+ it("should return the color prop and variant when passed a valid color variant", function () {
14
+ var colorProp = isColorVariantValue("hiContrast", AVAILABLE_COLOR_VARIANTS);
15
+ expect(colorProp).toEqual({
16
+ color: "hiContrast"
17
+ });
18
+ });
19
+ it("should return the css prop and color value when passed a value from the getColorScaleValueByUseCase() function", function () {
20
+ var colorProp = isColorVariantValue("$colors$warning9", AVAILABLE_COLOR_VARIANTS);
21
+ expect(colorProp).toEqual({
22
+ css: {
23
+ color: "$colors$warning9"
24
+ }
25
+ });
26
+ });
12
27
  });
@@ -3,7 +3,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  import _extends from "@babel/runtime/helpers/extends";
4
4
  import { BaseIcon } from "@vitality-ds/icons";
5
5
  import { colorUseCases, css, getColorScaleValueByUseCase } from "@vitality-ds/system";
6
- import { AVAILABLE_MAX_LINES, AVAILABLE_VARIANTS } from "../constants";
6
+ import { AVAILABLE_MAX_LINES, AVAILABLE_VARIANTS } from "../constants/variants";
7
7
  import { getMaxLines, getMaxLinesVariants, getVariantStyles } from "./helpers";
8
8
  var text = colorUseCases.text;
9
9
  var overflowSharedStyles = {