( withLabel: ControlElement, schema?: JsonSchema )
| 55 | * @returns {LabelDescription} |
| 56 | */ |
| 57 | export const createLabelDescriptionFrom = ( |
| 58 | withLabel: ControlElement, |
| 59 | schema?: JsonSchema |
| 60 | ): LabelDescription => { |
| 61 | const labelProperty = withLabel.label; |
| 62 | if (typeof labelProperty === 'boolean') { |
| 63 | return labelDescription(deriveLabel(withLabel, schema), labelProperty); |
| 64 | } |
| 65 | if (typeof labelProperty === 'string') { |
| 66 | return labelDescription(labelProperty, true); |
| 67 | } |
| 68 | if (typeof labelProperty === 'object') { |
| 69 | const label = |
| 70 | typeof labelProperty.text === 'string' |
| 71 | ? labelProperty.text |
| 72 | : deriveLabel(withLabel, schema); |
| 73 | const show = |
| 74 | typeof labelProperty.show === 'boolean' ? labelProperty.show : true; |
| 75 | return labelDescription(label, show); |
| 76 | } |
| 77 | return labelDescription(deriveLabel(withLabel, schema), true); |
| 78 | }; |
| 79 | |
| 80 | const labelDescription = (text: string, show: boolean): LabelDescription => ({ |
| 81 | text: text, |
no test coverage detected
searching dependent graphs…