From de8d0ff7f26f6d7905a51d903b3a94c6cbe1771e Mon Sep 17 00:00:00 2001 From: Jacques Nel Date: Thu, 12 Aug 2021 14:15:34 +0200 Subject: [PATCH] semantic-ui: add submit button, email, url, date widgets (#2224) * feat: add button,email,date widgets feat: include widgets Revert test: updates tests * chore: tests updated Co-authored-by: Jacques --- .../src/DateTimeWidget/DateTimeWidget.js | 65 +++++++ .../semantic-ui/src/DateTimeWidget/index.js | 2 + .../semantic-ui/src/DateWidget/DateWidget.js | 63 +++++++ packages/semantic-ui/src/DateWidget/index.js | 2 + .../src/EmailWidget/EmailWidget.js | 82 +++++++++ packages/semantic-ui/src/EmailWidget/index.js | 2 + .../src/SubmitButton/SubmitButton.js | 4 + .../semantic-ui/src/SubmitButton/index.js | 2 + packages/semantic-ui/src/Theme/Theme.js | 3 + .../semantic-ui/src/URLWidget/URLWidget.js | 64 +++++++ packages/semantic-ui/src/URLWidget/index.js | 2 + packages/semantic-ui/src/Widgets/Widgets.js | 9 +- .../test/__snapshots__/Array.test.js.snap | 45 +++-- .../test/__snapshots__/Form.test.js.snap | 167 +++++++++--------- .../test/__snapshots__/Object.test.js.snap | 15 +- 15 files changed, 410 insertions(+), 117 deletions(-) create mode 100644 packages/semantic-ui/src/DateTimeWidget/DateTimeWidget.js create mode 100644 packages/semantic-ui/src/DateTimeWidget/index.js create mode 100644 packages/semantic-ui/src/DateWidget/DateWidget.js create mode 100644 packages/semantic-ui/src/DateWidget/index.js create mode 100644 packages/semantic-ui/src/EmailWidget/EmailWidget.js create mode 100644 packages/semantic-ui/src/EmailWidget/index.js create mode 100644 packages/semantic-ui/src/SubmitButton/SubmitButton.js create mode 100644 packages/semantic-ui/src/SubmitButton/index.js create mode 100644 packages/semantic-ui/src/URLWidget/URLWidget.js create mode 100644 packages/semantic-ui/src/URLWidget/index.js diff --git a/packages/semantic-ui/src/DateTimeWidget/DateTimeWidget.js b/packages/semantic-ui/src/DateTimeWidget/DateTimeWidget.js new file mode 100644 index 0000000000..429cae9143 --- /dev/null +++ b/packages/semantic-ui/src/DateTimeWidget/DateTimeWidget.js @@ -0,0 +1,65 @@ +/* eslint-disable react/prop-types */ +import React from "react"; +import { utils } from "@rjsf/core"; +import { getSemanticProps } from "../util"; +import { Form } from "semantic-ui-react"; + +const { localToUTC, utcToLocal, getDisplayLabel } = utils; + +function DateTimeWidget(props) { + const { + id, + required, + readonly, + disabled, + name, + label, + schema, + uiSchema, + value, + onChange, + onBlur, + onFocus, + autofocus, + options, + formContext, + } = props; + const semanticProps = getSemanticProps({ formContext, options }); + const _onChange = ({ target: { value } }) => onChange && onChange(localToUTC(value)); + const _onBlur = () => onBlur && onBlur(id, value); + const _onFocus = () => onFocus && onFocus(id, value); + const dateValue = utcToLocal(value); + const displayLabel = getDisplayLabel( + schema, + uiSchema + /* TODO: , rootSchema */ + ); + return ( + + ); +} + +DateTimeWidget.defaultProps = { + options: { + semantic: { + fluid: true, + inverted: false, + }, + }, +}; + +export default DateTimeWidget; diff --git a/packages/semantic-ui/src/DateTimeWidget/index.js b/packages/semantic-ui/src/DateTimeWidget/index.js new file mode 100644 index 0000000000..0db366167f --- /dev/null +++ b/packages/semantic-ui/src/DateTimeWidget/index.js @@ -0,0 +1,2 @@ +export { default } from './DateTimeWidget'; +export * from './DateTimeWidget'; diff --git a/packages/semantic-ui/src/DateWidget/DateWidget.js b/packages/semantic-ui/src/DateWidget/DateWidget.js new file mode 100644 index 0000000000..7da21c6bb0 --- /dev/null +++ b/packages/semantic-ui/src/DateWidget/DateWidget.js @@ -0,0 +1,63 @@ +/* eslint-disable react/prop-types */ +import React from "react"; +import { getSemanticProps } from "../util"; +import { Form } from "semantic-ui-react"; +import { utils } from "@rjsf/core"; + +const { getDisplayLabel } = utils; +function DateWidget(props) { + const { + id, + required, + readonly, + disabled, + name, + label, + value, + onChange, + onBlur, + onFocus, + autofocus, + options, + formContext, + schema, + uiSchema, + } = props; + const semanticProps = getSemanticProps({ formContext, options }); + const _onChange = ({ target: { value } }) => onChange && onChange(value); + const _onBlur = () => onBlur && onBlur(id, value); + const _onFocus = () => onFocus && onFocus(id, value); + const displayLabel = getDisplayLabel( + schema, + uiSchema + /* TODO: , rootSchema */ + ); + return ( + + ); +} + +DateWidget.defaultProps = { + options: { + semantic: { + fluid: true, + inverted: false, + }, + }, +}; + +export default DateWidget; diff --git a/packages/semantic-ui/src/DateWidget/index.js b/packages/semantic-ui/src/DateWidget/index.js new file mode 100644 index 0000000000..923b0077fb --- /dev/null +++ b/packages/semantic-ui/src/DateWidget/index.js @@ -0,0 +1,2 @@ +export { default } from './DateWidget'; +export * from './DateWidget'; diff --git a/packages/semantic-ui/src/EmailWidget/EmailWidget.js b/packages/semantic-ui/src/EmailWidget/EmailWidget.js new file mode 100644 index 0000000000..e7caa0e8c4 --- /dev/null +++ b/packages/semantic-ui/src/EmailWidget/EmailWidget.js @@ -0,0 +1,82 @@ +import React from "react"; +import PropTypes from "prop-types"; +import { Form } from "semantic-ui-react"; +import { getSemanticProps } from "../util"; +import { utils } from "@rjsf/core"; + +const { getDisplayLabel } = utils; +function EmailWidget(props) { + const { + id, + required, + readonly, + disabled, + name, + label, + schema, + uiSchema, + value, + onChange, + onBlur, + onFocus, + autofocus, + options, + formContext, + } = props; + const semanticProps = getSemanticProps({ formContext, options }); + // eslint-disable-next-line no-shadow + const _onChange = ({ target: { value } }) => + onChange(value === "" ? options.emptyValue : value); + const _onBlur = () => onBlur && onBlur(id, value); + const _onFocus = () => onFocus && onFocus(id, value); + const displayLabel = getDisplayLabel( + schema, + uiSchema + /* TODO: , rootSchema */ + ); + return ( + + ); +} + +EmailWidget.defaultProps = { + options: { + semantic: { + fluid: true, + inverted: false, + }, + }, +}; + + + + +EmailWidget.defaultProps = { + options: { + semantic: { + fluid: true, + inverted: false, + }, + }, +}; + + +EmailWidget.propTypes = { + options: PropTypes.object, +}; + +export default EmailWidget; diff --git a/packages/semantic-ui/src/EmailWidget/index.js b/packages/semantic-ui/src/EmailWidget/index.js new file mode 100644 index 0000000000..c48979eea8 --- /dev/null +++ b/packages/semantic-ui/src/EmailWidget/index.js @@ -0,0 +1,2 @@ +export { default } from './EmailWidget'; +export * from './EmailWidget'; diff --git a/packages/semantic-ui/src/SubmitButton/SubmitButton.js b/packages/semantic-ui/src/SubmitButton/SubmitButton.js new file mode 100644 index 0000000000..afab81e7fb --- /dev/null +++ b/packages/semantic-ui/src/SubmitButton/SubmitButton.js @@ -0,0 +1,4 @@ +import React from "react"; +import { Button } from "semantic-ui-react"; +export default () => ( - + `; @@ -155,14 +154,13 @@ exports[`array fields checkboxes 1`] = ` -
- -
+ `; @@ -272,13 +270,12 @@ exports[`array fields fixed array 1`] = ` -
- -
+ `; diff --git a/packages/semantic-ui/test/__snapshots__/Form.test.js.snap b/packages/semantic-ui/test/__snapshots__/Form.test.js.snap index 3728051b95..a5d71731f7 100644 --- a/packages/semantic-ui/test/__snapshots__/Form.test.js.snap +++ b/packages/semantic-ui/test/__snapshots__/Form.test.js.snap @@ -9,14 +9,13 @@ exports[`single fields null field 1`] = `
-
- -
+ `; @@ -49,14 +48,13 @@ exports[`single fields number field 1`] = `
-
- -
+ `; @@ -82,14 +80,13 @@ exports[`single fields string field format data-url 1`] = `

-
- -
+ `; @@ -102,30 +99,32 @@ exports[`single fields string field format email 1`] = `
- -
-
- +
+ +
+
+ `; @@ -138,30 +137,32 @@ exports[`single fields string field format uri 1`] = `
- -
-
- +
+ +
+
+ `; @@ -194,14 +195,13 @@ exports[`single fields string field regular 1`] = ` -
- -
+ `; @@ -237,13 +237,12 @@ exports[`single fields unsupported field 1`] = ` -
- -
+ `; diff --git a/packages/semantic-ui/test/__snapshots__/Object.test.js.snap b/packages/semantic-ui/test/__snapshots__/Object.test.js.snap index 86f8cfd3aa..b7ff85edfc 100644 --- a/packages/semantic-ui/test/__snapshots__/Object.test.js.snap +++ b/packages/semantic-ui/test/__snapshots__/Object.test.js.snap @@ -68,13 +68,12 @@ exports[`object fields object 1`] = ` -
- -
+ `;