UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

31 lines (30 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setCanvasKitTags = void 0; /// <reference types="@types/node" /> const version_1 = require("@workday/canvas-kit-react/version"); const canvas_kit_styling_1 = require("@workday/canvas-kit-styling"); // Only add the major version tag for development and test environments const versionTag = process.env.NODE_ENV === 'production' ? version_1.version : version_1.version.split('.')[0]; /** * This function returns data attributes for tagging * We use this to track when and where our components render. It also allows us to see what version is rendering. */ function setCanvasKitTags(displayName = '', props = {}) { // Do not add tags for subcomponents. E.g. Card.Text const shouldAddTag = displayName.length && !displayName.includes('.'); if (shouldAddTag) { // Append variant name to tag, if available: `primary-button-inverse` const componentTypeTag = props.variant ? `${displayName} ${props.variant}` : displayName; return { ['data-uxi-canvas-kit-version']: versionTag, ['data-uxi-canvas-kit-component-type']: (0, canvas_kit_styling_1.slugify)(componentTypeTag), }; } // We need to explictily pass these attributes with `undefined` so they will be removed from the DOM. return { ['data-uxi-canvas-kit-version']: undefined, ['data-uxi-canvas-kit-component-type']: undefined, }; } exports.setCanvasKitTags = setCanvasKitTags;