Skip to content

Commit c25ceab

Browse files
committed
feat(pf4): add placeholder slider
1 parent b57b7f0 commit c25ceab

File tree

9 files changed

+61
-6
lines changed

9 files changed

+61
-6
lines changed

packages/pf4-component-mapper/src/files/component-mapper.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import TimePicker from './time-picker';
1414
import Switch from './switch';
1515
import PlainText from './plain-text';
1616
import DualListSelect from './dual-list-select';
17+
import Slider from './slider';
1718

1819
const mapper = {
1920
[componentTypes.TEXT_FIELD]: TextField,
@@ -29,7 +30,8 @@ const mapper = {
2930
[componentTypes.SWITCH]: Switch,
3031
[componentTypes.PLAIN_TEXT]: PlainText,
3132
[componentTypes.FIELD_ARRAY]: FieldArray,
32-
[componentTypes.DUAL_LIST_SELECT]: DualListSelect
33+
[componentTypes.DUAL_LIST_SELECT]: DualListSelect,
34+
[componentTypes.SLIDER]: Slider
3335
};
3436

3537
export default mapper;
@@ -44,7 +46,8 @@ export const components = {
4446
TimePicker,
4547
Switch,
4648
PlainText,
47-
DualListSelect
49+
DualListSelect,
50+
Slider
4851
};
4952

5053
export const rawComponents = {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
4+
import FormGroup from '../common/form-group';
5+
import { Badge, Grid, GridItem } from '@patternfly/react-core';
6+
7+
import './slider.scss';
8+
9+
const Slider = (props) => {
10+
const { label, isRequired, helperText, meta, description, input, isReadOnly, isDisabled, id, ...rest } = useFieldApi(props);
11+
12+
return (
13+
<FormGroup label={label} isRequired={isRequired} helperText={helperText} meta={meta} description={description} id={id || input.name}>
14+
<Grid gutter="md">
15+
<GridItem span={10}>
16+
<input
17+
className={'ddorg__pf4-component-mapper__dual-list-slider-input '}
18+
{...rest}
19+
{...input}
20+
type="range"
21+
disabled={isDisabled || isReadOnly}
22+
/>
23+
</GridItem>
24+
<GridItem span={2}>
25+
<Badge isRead>{input.value || rest.max / 2}</Badge>
26+
</GridItem>
27+
</Grid>
28+
</FormGroup>
29+
);
30+
};
31+
32+
Slider.propTypes = {
33+
label: PropTypes.node,
34+
isReadOnly: PropTypes.bool,
35+
isRequired: PropTypes.bool,
36+
helperText: PropTypes.node,
37+
description: PropTypes.node,
38+
isDisabled: PropTypes.bool,
39+
id: PropTypes.string
40+
};
41+
42+
export default Slider;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ddorg__pf4-component-mapper__dual-list-slider-input {
2+
width: 100%
3+
}

packages/pf4-component-mapper/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export { default as FieldArray } from './files/field-array';
77
export { default as PlainText } from './files/plain-text';
88
export { default as Radio } from './files/radio';
99
export { default as Select } from './files/select';
10+
export { default as Slider } from './files/slider';
1011
export { default as SubForm } from './files/sub-form';
1112
export { default as Switch } from './files/switch';
1213
export { default as Tabs } from './files/tabs';

packages/pf4-component-mapper/src/tests/form-fields.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ describe('FormFields', () => {
264264
componentTypes.DATE_PICKER,
265265
componentTypes.TIME_PICKER,
266266
componentTypes.SWITCH,
267-
componentTypes.SELECT
267+
componentTypes.SELECT,
268+
componentTypes.SLIDER
268269
].forEach((component) => {
269270
describe(`Component type: ${component}`, () => {
270271
beforeEach(() => {
@@ -441,7 +442,7 @@ describe('FormFields', () => {
441442
.first()
442443
.props().disabled
443444
).toEqual(true);
444-
} else if ([componentTypes.CHECKBOX, componentTypes.RADIO, componentTypes.SWITCH].includes(component)) {
445+
} else if ([componentTypes.CHECKBOX, componentTypes.RADIO, componentTypes.SWITCH, componentTypes.SLIDER].includes(component)) {
445446
expect(
446447
wrapper
447448
.find('input')

packages/pf4-component-mapper/src/tests/wizard/__snapshots__/wizard.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
1313
"plain-text": [Function],
1414
"radio": [Function],
1515
"select": [Function],
16+
"slider": [Function],
1617
"sub-form": [Function],
1718
"switch": [Function],
1819
"tabs": [Function],
@@ -1091,6 +1092,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
10911092
"plain-text": [Function],
10921093
"radio": [Function],
10931094
"select": [Function],
1095+
"slider": [Function],
10941096
"sub-form": [Function],
10951097
"switch": [Function],
10961098
"tabs": [Function],

packages/react-renderer-demo/src/app/pages/component-example/slider.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import ComponentText from '@docs/components/component-example-text';
44
import useComponentExample from '../../src/hooks/use-component-example';
55
import componentTypes from '@data-driven-forms/react-form-renderer/dist/cjs/component-types';
66
import MUISlider from '@data-driven-forms/mui-component-mapper/dist/cjs/slider';
7+
import PF4Slider from '@data-driven-forms/pf4-component-mapper/dist/cjs/slider';
78

89
const PF3Slider = dynamic(() => import('@data-driven-forms/pf3-component-mapper/dist/cjs/slider'), {
910
ssr: false
1011
});
1112

1213
const mappers = {
1314
pf4: {
14-
[componentTypes.SLIDER]: () => 'Not released by Patternfly'
15+
[componentTypes.SLIDER]: PF4Slider
1516
},
1617
pf3: {
1718
[componentTypes.SLIDER]: PF3Slider

packages/react-renderer-demo/src/app/src/components/navigation/examples-texts/slider.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PF3 from '@docs/doc-components/pf3-slider.md';
33
import MUI from '@docs/doc-components/mui-slider.md';
4+
import PF4 from '@docs/doc-components/pf4-slider.md';
45

56
import PropTypes from 'prop-types';
67

@@ -13,7 +14,7 @@ const DocSlider = ({ activeMapper }) => {
1314
return <MUI />;
1415
}
1516

16-
return 'Not implemented yet';
17+
return <PF4 />;
1718
};
1819

1920
DocSlider.propTypes = {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a custom component. The official PatternFly 4 does not exist yet.

0 commit comments

Comments
 (0)