UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

231 lines (227 loc) • 4.99 kB
'use strict'; const inputWrapperArgTypes = { block: { defaultValue: false, control: { type: 'boolean' } }, contrast: { defaultValue: false, control: { type: 'boolean' } }, disabled: { defaultValue: false, control: { type: 'boolean' } }, placeholder: { defaultValue: '', control: { type: 'text' } }, size: { name: 'size (input)', // TODO: remove '(input)' defaultValue: 'medium', options: ['small', 'medium', 'large'], control: { type: 'radio' } }, validationStatus: { defaultValue: undefined, options: ['error', 'success', undefined], control: { type: 'radio' } } }; const textInputArgTypesUnsorted = { ...inputWrapperArgTypes, loading: { defaultValue: false, control: { type: 'boolean' } }, loaderPosition: { defaultValue: 'auto', options: ['auto', 'leading', 'trailing'], control: { type: 'radio' } }, monospace: { defaultValue: false, control: { type: 'boolean' } } }; // Alphabetize and optionally categorize the props const getTextInputArgTypes = category => Object.keys(textInputArgTypesUnsorted).sort().reduce((obj, key) => { obj[key] = category ? { // have to do weird type casting so we can spread the object ...textInputArgTypesUnsorted[key], table: { category } } : textInputArgTypesUnsorted[key]; return obj; }, {}); const textInputExcludedControlKeys = ['as', 'icon', 'leadingVisual', 'sx', 'trailingVisual', 'trailingAction']; const textInputWithTokensArgTypes = { hideTokenRemoveButtons: { defaultValue: false, type: 'boolean', table: { category: 'TextInputWithTokens props' } }, maxHeight: { type: 'string', defaultValue: 'none', description: 'Any valid value for the CSS max-height property', table: { category: 'TextInputWithTokens props' } }, preventTokenWrapping: { defaultValue: false, type: 'boolean', table: { category: 'TextInputWithTokens props' } }, size: { name: 'size (token size)', defaultValue: 'xlarge', options: ['small', 'medium', 'large', 'xlarge'], control: { type: 'radio' }, table: { category: 'TextInputWithTokens props' } }, visibleTokenCount: { defaultValue: 999, type: 'number', table: { category: 'TextInputWithTokens props' } } }; const formControlArgs = { required: false, disabled: false, labelChildren: 'Label', visuallyHidden: false, captionChildren: '', validationChildren: '', variant: 'error' }; const formControlArgTypes = { // FormControl required: { control: { type: 'boolean' }, table: { category: 'FormControl' } }, disabled: { control: { type: 'boolean' }, table: { category: 'FormControl' } }, // FormControl.Label labelChildren: { name: 'children', type: 'string', table: { category: 'FormControl.Label' } }, visuallyHidden: { type: 'boolean', table: { category: 'FormControl.Label' } }, // FormControl.Caption captionChildren: { name: 'children', type: 'string', table: { category: 'FormControl.Caption' } }, // FormControl.Validation validationChildren: { name: 'children', type: 'string', table: { category: 'FormControl.Validation' } }, variant: { control: { type: 'radio' }, options: ['error', 'success'], table: { category: 'FormControl.Validation' } } }; const formControlArgTypeKeys = Object.keys(formControlArgTypes); const formControlArgTypesWithoutValidation = formControlArgTypeKeys.reduce((acc, key) => { var _formControlArgTypes$; if (((_formControlArgTypes$ = formControlArgTypes[key].table) === null || _formControlArgTypes$ === void 0 ? void 0 : _formControlArgTypes$.category) !== 'FormControl.Validation') { acc[key] = formControlArgTypes[key]; } return acc; }, {}); const getFormControlArgsByChildComponent = ({ captionChildren, disabled, labelChildren, required, validationChildren, variant, visuallyHidden }) => ({ parentArgs: { disabled, required }, labelArgs: { visuallyHidden, children: labelChildren }, captionArgs: { children: captionChildren }, validationArgs: { children: validationChildren, variant } }); exports.formControlArgTypes = formControlArgTypes; exports.formControlArgTypesWithoutValidation = formControlArgTypesWithoutValidation; exports.formControlArgs = formControlArgs; exports.getFormControlArgsByChildComponent = getFormControlArgsByChildComponent; exports.getTextInputArgTypes = getTextInputArgTypes; exports.inputWrapperArgTypes = inputWrapperArgTypes; exports.textInputExcludedControlKeys = textInputExcludedControlKeys; exports.textInputWithTokensArgTypes = textInputWithTokensArgTypes;