Skip to content

Commit b0bfdeb

Browse files
committed
Added Semantic-UI form example
+ Added style prop
1 parent 502e661 commit b0bfdeb

File tree

4 files changed

+56
-32
lines changed

4 files changed

+56
-32
lines changed

src/components/MultiRangeSlider.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const MultiRangeSlider = function (props: MultiRangeSliderProps) {
4040
showLabels = false,
4141
disabled = false,
4242
inverted = false,
43-
color = 'green'
43+
color = 'green',
44+
style
4445
} = props
4546

4647
/**
@@ -87,7 +88,7 @@ const MultiRangeSlider = function (props: MultiRangeSliderProps) {
8788
const disabledClass = disabled ? 'disabled' : ''
8889

8990
return (
90-
<div className='slider-parent'>
91+
<div className='slider-parent' style={style}>
9192
<input
9293
type="range"
9394
min={defaultMinValue}

src/components/SingleRangeSlider.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const SingleRangeSlider = function (props: SingleRangeSliderProps) {
3434
step = 1,
3535
disabled = false,
3636
inverted = false,
37+
style,
3738
onChange
3839
} = props
3940

@@ -71,7 +72,7 @@ const SingleRangeSlider = function (props: SingleRangeSliderProps) {
7172
const disabledClass = disabled ? 'disabled' : ''
7273

7374
return (
74-
<div className='slider-parent'>
75+
<div className='slider-parent' style={style}>
7576
<input
7677
type="range"
7778
min={defaultMinValue}

src/stories/SemanticUI.stories.tsx

+47-29
Original file line numberDiff line numberDiff line change
@@ -117,53 +117,71 @@ export const SemanticGrid = () => {
117117
}
118118

119119
export const SemanticForm = () => {
120-
const [value, setValue] = useState<number>(40)
120+
const [valueSingle, setValueSingle] = useState<number>(40)
121+
const [[minValue, maxValue], setValuesMulti] = useState<[number, number]>([30, 80])
121122

122123
/**
123-
* Handles changes.
124+
* Handles changes on single range sliders.
124125
*
125126
* @param newValue - New value.
126127
*/
127-
function handleChange (newValue: number) {
128-
setValue(newValue)
128+
function handleChangeOnSingle (newValue: number) {
129+
setValueSingle(newValue)
130+
}
131+
132+
/**
133+
* Handles changes on multi range sliders.
134+
*
135+
* @param newMinValue - New min value.
136+
* @param newMaxValue - New max value.
137+
*/
138+
function handleChangeOnMulti (newMinValue: number, newMaxValue: number) {
139+
setValuesMulti([newMinValue, newMaxValue])
129140
}
130141

131142
return (
132143
<Container>
133144
<Grid>
145+
<Grid.Row columns={1}>
146+
<Grid.Column>
147+
<h2>You can use Sliders inside <a href='https://react.semantic-ui.com/collections/form/' target='_blank' rel='noreferrer'>Semantic-UI forms</a></h2>
148+
</Grid.Column>
149+
</Grid.Row>
150+
134151
<Grid.Row columns={1}>
135152
<Grid.Column>
136153
<Form>
137-
<Form.Group widths='equal'>
154+
<Form.Group widths={4}>
138155
<Form.Input fluid label='First name' placeholder='First name' />
139156
<Form.Input fluid label='Last name' placeholder='Last name' />
140157
</Form.Group>
141-
<Form.Group inline>
142-
<label>Size</label>
143-
<Form.Radio
144-
label='Small'
145-
value='sm'
146-
checked
147-
/>
148-
<Form.Radio
149-
label='Medium'
150-
value='md'
151-
/>
152-
<Form.Radio
153-
label='Large'
154-
value='lg'
155-
/>
156-
</Form.Group>
157158
<Form.Group>
158-
<SingleRangeSlider
159-
defaultMinValue={0}
160-
defaultMaxValue={100}
161-
value={value}
162-
color='red'
163-
onChange={handleChange}
164-
/>
159+
<Form.Field width={4}>
160+
<label>Happiness</label>
161+
<SingleRangeSlider
162+
style={{ marginTop: '5%', marginBottom: '5%' }}
163+
defaultMinValue={0}
164+
defaultMaxValue={100}
165+
value={valueSingle}
166+
color='green'
167+
onChange={handleChangeOnSingle}
168+
/>
169+
</Form.Field>
170+
171+
<Form.Field width={4}>
172+
<label>Earning range</label>
173+
<MultiRangeSlider
174+
style={{ marginTop: '5%', marginBottom: '5%' }}
175+
defaultMinValue={0}
176+
defaultMaxValue={100}
177+
minValue={minValue}
178+
maxValue={maxValue}
179+
color='violet'
180+
showLabels
181+
onChange={handleChangeOnMulti}
182+
/>
183+
</Form.Field>
165184
</Form.Group>
166-
<Form.Checkbox label='I agree to the Terms and Conditions' />
167185
<Form.Button>Submit</Form.Button>
168186
</Form>
169187
</Grid.Column>

src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CSSProperties } from 'react'
2+
13
/** Allowed colors. */
24
type RangeColor = 'red' |
35
'orange' |
@@ -28,6 +30,8 @@ interface SliderProps {
2830
disabled?: boolean;
2931
/** A slider can have its colors inverted for contrast on a dark background. Default to `false`. */
3032
inverted?: boolean;
33+
/** Component custom styles. */
34+
style?: CSSProperties;
3135
}
3236

3337
export type { RangeColor, SliderProps }

0 commit comments

Comments
 (0)