Sha256: 0891dd89270bd8f38d835c48703d8179550bc157bba419c3df06f8d910bf31f6

Contents?: true

Size: 1.88 KB

Versions: 355

Compression:

Stored size: 1.88 KB

Contents

/**
 * Defines a set of helper functions used to construct a component following
 * Playbook's patterns.
 */
import classnames from 'classnames'

/**
 *
 * @param {String} prefix the prefix to be used on the dash separated prop (data, aria, etc...)
 * @param {Object} data the object containing the data to derive the props from.
 * @returns {Object} an object whose keys have the prefix added to them.
 */
const buildPrefixedProps = (prefix: string, data: {[key: string]: any}) => 
  Object.keys(data).reduce((props: {[key: string]: any}, key: string) => {
    props[`${prefix}-${key}`] = data[key]
    return props
  }, {})

/**
 * Represent a "No-Operation" function that can be used as a sensible
 * default to event handlers in the absence of a value.
 *
 * @returns {() => {}} the noop function.
 */
export const noop = (): void => { void 0 }

/**
 * Maps a given aria object into HTML valid aria attribtues and their values.
 *
 * @param {Object} aria the object containing the aria prop values.
 * @returns {Object} an object holding the HTML valid aria props and their values.
 */
export const buildAriaProps = (aria: {[key: string]: string}): {[key: string]: string} => 
  buildPrefixedProps('aria', aria)

/**
 * Maps a given data object into HTML valid data attribtues and their values.
 *
 * @param {Object} data the object containing the data prop values.
 * @returns {Object} an object holding the HTML valid data props and their values.
 */
export const buildDataProps = (data: {[key: string]: any}) => buildPrefixedProps('data', data)

/**
 * Builds a Playbook valid root className off of the incoming css rules.
 *
 * @param {Object} rules a 'classnames' compliant rules object, used to derive the root className.
 * @returns {String} the derived root className value.
 */
export const buildCss = (...rules: (string | { [x: string]: string | boolean; })[]): string => classnames(rules).replace(/\s/g, '_')

Version data entries

355 entries across 355 versions & 1 rubygems

Version Path
playbook_ui-13.1.0 app/pb_kits/playbook/utilities/props.ts
playbook_ui-13.0.0.pre.alpha.PLAY966collapsiblenav41129 app/pb_kits/playbook/utilities/props.ts
playbook_ui-13.0.0.pre.alpha.PLAY966collapsiblenav41128 app/pb_kits/playbook/utilities/props.ts
playbook_ui-13.0.0.pre.alpha.PLAY966collapsiblenav41126 app/pb_kits/playbook/utilities/props.ts
playbook_ui-13.0.0.pre.alpha.salesbookmismatchingdate1120 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.39.0.pre.alpha.salesbookmismatchingdate1117 app/pb_kits/playbook/utilities/props.ts
playbook_ui-13.0.0 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.39.0.pre.alpha.PLAY966collapsiblenav41115 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.39.0.pre.alpha.salesbookmismatchingdate1114 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.39.0 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.38.0.pre.alpha.PBNTR78selectkitmultipleprop1094 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.38.0.pre.alpha.PLAY932removemomentqp1088 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.38.0.pre.alpha.PLAY966collapsiblenav41086 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.38.0.pre.alpha.audiencesalpha1083 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.38.0.pre.alpha.PLAY966collapsiblenav41082 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.38.0.pre.alpha.PLAYaddingdatapropselectkit1080 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31078 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.38.0.pre.alpha.playbook123801077 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31074 app/pb_kits/playbook/utilities/props.ts
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31073 app/pb_kits/playbook/utilities/props.ts