Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit a7af28d

Browse files
Merge pull request #836 from intellihr/release/375
Release 375
2 parents afd6468 + 1684630 commit a7af28d

File tree

6 files changed

+111
-2
lines changed

6 files changed

+111
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@intellihr/ui-components",
33
"description": "A common React components library that is used in our company",
4-
"version": "48.0.0",
4+
"version": "48.0.1",
55
"main": "./dist/",
66
"types": "./types/index.d.ts",
77
"files": [

src/domain/Forms/VerticalForm/VerticalForm.examples.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,68 @@ initialState = { textInputValue: '' };
317317
</VerticalForm.RightAlignControls>
318318
</VerticalForm>
319319
```
320+
321+
Field with label suffix
322+
323+
```jsx
324+
import { ButtonGroup, Button } from '@Domain/Buttons';
325+
import { SelectInput } from '@Domain/Inputs';
326+
327+
initialState = { people: [], parentGoalId: '' };
328+
329+
<VerticalForm
330+
>
331+
<VerticalForm.Field
332+
inputName='people'
333+
label='Set Goal for'
334+
>
335+
<SelectInput
336+
name='people'
337+
value={state.people}
338+
options={[
339+
{
340+
label: 'Lyanna Moreton',
341+
value: 1
342+
},
343+
{
344+
label: 'Donna Summer',
345+
value: 2
346+
}
347+
]}
348+
onChange={value => { value.length > 1 ? setState({ people: value, parentGoalId:'' }) : setState({ people: value }) }}
349+
isMultiSelect
350+
/>
351+
</VerticalForm.Field>
352+
<VerticalForm.Field
353+
inputName='parentGoalId'
354+
label='Parent Goal'
355+
labelSuffix='individuals only'
356+
tooltipMessage='Parent goals are related to an individual and cannot be selected for multiple people.'
357+
tooltipProps={{width: 300}}
358+
>
359+
<SelectInput
360+
isDisabled={state.people.length > 1}
361+
name='parentGoalId'
362+
value={state.parentGoalId}
363+
options={[
364+
{
365+
label: 'Sale Goal',
366+
value: 1
367+
},
368+
{
369+
label: 'IT Goal',
370+
value: 2
371+
}
372+
]}
373+
onChange={value => setState({ parentGoalId: value })}
374+
/>
375+
</VerticalForm.Field>
376+
<VerticalForm.RightAlignControls>
377+
<Button
378+
type='primary'
379+
>
380+
Submit me :)
381+
</Button>
382+
</VerticalForm.RightAlignControls>
383+
</VerticalForm>
384+
```

src/domain/Forms/VerticalForm/subcomponents/Field.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,18 @@ describe('<Field />', () => {
137137

138138
expect(wrapper).toMatchSnapshot()
139139
})
140+
141+
it(`should render a vertical form field with label suffix`, () => {
142+
const wrapper = shallow(
143+
<Field
144+
inputName='testInput'
145+
label='This is a test input'
146+
labelSuffix='only test'
147+
>
148+
Children
149+
</Field>
150+
)
151+
152+
expect(wrapper).toMatchSnapshot()
153+
})
140154
})

src/domain/Forms/VerticalForm/subcomponents/Field.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ interface IVerticalFormFieldProps {
2323
isRequired?: boolean
2424
/** Text displayed above the input */
2525
label?: string
26+
/** Arbitrary text displayed after the label, it will replace the required label when isRequired is true */
27+
labelSuffix?: string
2628
/** Descriptive text displayed above the input */
2729
description?: string
2830
/** action text link displayed below the input */
@@ -84,14 +86,16 @@ class Field extends React.PureComponent<IVerticalFormFieldProps, never> {
8486
const {
8587
inputName,
8688
isRequired,
87-
label
89+
label,
90+
labelSuffix
8891
} = this.props
8992

9093
if (label) {
9194
return (
9295
<StyledInputLabel
9396
htmlFor={inputName}
9497
isRequired={isRequired!}
98+
labelSuffix={labelSuffix}
9599
>
96100
{label}
97101
{this.tooltip}

src/domain/Forms/VerticalForm/subcomponents/__snapshots__/Field.test.tsx.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ exports[`<Field /> should render a vertical form field with error messages 1`] =
121121
</styled.div>
122122
`;
123123

124+
exports[`<Field /> should render a vertical form field with label suffix 1`] = `
125+
<styled.div>
126+
<styled.div>
127+
<styled.label
128+
htmlFor="testInput"
129+
isRequired={false}
130+
labelSuffix="only test"
131+
>
132+
This is a test input
133+
</styled.label>
134+
</styled.div>
135+
Children
136+
</styled.div>
137+
`;
138+
124139
exports[`<Field /> should render a vertical form field with nothing 1`] = `<styled.div />`;
125140

126141
exports[`<Field /> should render a vertical form field with regular props 1`] = `

src/domain/Forms/VerticalForm/subcomponents/style.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { styleForMargins } from '../../../Spacers/services/margins'
55

66
interface IStyledInputLabelProps {
77
isRequired: boolean
8+
labelSuffix?: string
89
}
910

1011
interface IFieldWrapperProps {
@@ -52,6 +53,16 @@ const StyledInputLabel = styled.label`
5253
}
5354
`
5455
}}
56+
57+
${(props: IStyledInputLabelProps) => props.labelSuffix && css`
58+
&::after {
59+
color: ${Variables.Color.n400};
60+
content: " - ${props.labelSuffix}";
61+
font-size: ${Variables.FontSize.fzSmall}px;
62+
font-style: italic;
63+
}
64+
`
65+
}}
5566
`
5667

5768
const StyledDescription = styled.div`

0 commit comments

Comments
 (0)