File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import Hint , { HintProps } from '../hint/Hint' ;
3+ import Label , { LabelProps } from '../label/Label' ;
4+ import ErrorMessage , { ErrorMessageProps } from '../error-message/ErrorMessage' ;
5+
6+ interface LabelBlockProps {
7+ elementId ?: string ;
8+ label ?: string ;
9+ labelProps ?: LabelProps ;
10+ hint ?: string ;
11+ hintProps ?: HintProps ;
12+ error ?: string | boolean ;
13+ errorProps ?: ErrorMessageProps ;
14+ }
15+
16+ const LabelBlock : React . FC < LabelBlockProps > = ( {
17+ elementId,
18+ label,
19+ labelProps,
20+ hint,
21+ hintProps,
22+ error,
23+ errorProps,
24+ } ) => (
25+ < >
26+ { label ? (
27+ < Label id = { elementId ? `${ elementId } --label` : undefined } htmlFor = { elementId } { ...labelProps } >
28+ { label }
29+ </ Label >
30+ ) : null }
31+ { hint ? (
32+ < Hint id = { elementId ? `${ elementId } --hint` : undefined } { ...hintProps } >
33+ { hint }
34+ </ Hint >
35+ ) : null }
36+ { error && typeof error === 'string' ? (
37+ < ErrorMessage id = { elementId ? `${ elementId } --error-message` : undefined } { ...errorProps } >
38+ { error }
39+ </ ErrorMessage >
40+ ) : null }
41+ </ >
42+ ) ;
43+
44+ export default LabelBlock ;
Original file line number Diff line number Diff line change 1+ export const getRandomString = ( length : number = 5 ) => {
2+ const randomNumber = Math . random ( ) + 1 ;
3+ return randomNumber . toString ( 36 ) . substring ( 2 , length + 2 ) ;
4+ } ;
5+
6+ export const generateRandomName = ( prefix ?: string ) => {
7+ const randomString = getRandomString ( ) ;
8+ return prefix ? `${ prefix } _${ randomString } ` : randomString ;
9+ } ;
You can’t perform that action at this time.
0 commit comments