-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
7c2d9f1
commit de8d0ff
Showing
15 changed files
with
410 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Form.Input | ||
key={id} | ||
id={id} | ||
type="datetime-local" | ||
label={displayLabel ? label || schema.title : false} | ||
required={required} | ||
autoFocus={autofocus} | ||
disabled={disabled || readonly} | ||
name={name} | ||
{...semanticProps} | ||
value={dateValue} | ||
onChange={_onChange} | ||
onBlur={_onBlur} | ||
onFocus={_onFocus} | ||
/> | ||
); | ||
} | ||
|
||
DateTimeWidget.defaultProps = { | ||
options: { | ||
semantic: { | ||
fluid: true, | ||
inverted: false, | ||
}, | ||
}, | ||
}; | ||
|
||
export default DateTimeWidget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './DateTimeWidget'; | ||
export * from './DateTimeWidget'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Form.Input | ||
key={id} | ||
id={id} | ||
type="date" | ||
label={displayLabel ? label || schema.title : false} | ||
required={required} | ||
autoFocus={autofocus} | ||
disabled={disabled || readonly} | ||
name={name} | ||
{...semanticProps} | ||
value={value || value === 0 ? value : ""} | ||
onChange={_onChange} | ||
onBlur={_onBlur} | ||
onFocus={_onFocus} | ||
/> | ||
); | ||
} | ||
|
||
DateWidget.defaultProps = { | ||
options: { | ||
semantic: { | ||
fluid: true, | ||
inverted: false, | ||
}, | ||
}, | ||
}; | ||
|
||
export default DateWidget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './DateWidget'; | ||
export * from './DateWidget'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Form.Input | ||
key={id} | ||
id={id} | ||
type="email" | ||
label={displayLabel ? label || schema.title : false} | ||
required={required} | ||
autoFocus={autofocus} | ||
disabled={disabled || readonly} | ||
name={name} | ||
{...semanticProps} | ||
value={value || value === 0 ? value : ""} | ||
onChange={_onChange} | ||
onBlur={_onBlur} | ||
onFocus={_onFocus} | ||
/> | ||
); | ||
} | ||
|
||
EmailWidget.defaultProps = { | ||
options: { | ||
semantic: { | ||
fluid: true, | ||
inverted: false, | ||
}, | ||
}, | ||
}; | ||
|
||
|
||
|
||
|
||
EmailWidget.defaultProps = { | ||
options: { | ||
semantic: { | ||
fluid: true, | ||
inverted: false, | ||
}, | ||
}, | ||
}; | ||
|
||
|
||
EmailWidget.propTypes = { | ||
options: PropTypes.object, | ||
}; | ||
|
||
export default EmailWidget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './EmailWidget'; | ||
export * from './EmailWidget'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from "react"; | ||
import { Button } from "semantic-ui-react"; | ||
export default () => (<Button content="Submit" type="submit" primary />); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './SubmitButton'; | ||
export * from './SubmitButton'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import { Form } from "semantic-ui-react"; | ||
import { getSemanticProps } from "../util"; | ||
import { utils } from "@rjsf/core"; | ||
|
||
const { getDisplayLabel } = utils; | ||
function URLWidget(props) { | ||
const { | ||
id, | ||
name, | ||
label, | ||
value, | ||
required, | ||
readonly, | ||
disabled, | ||
onChange, | ||
onBlur, | ||
onFocus, | ||
autofocus, | ||
options, | ||
schema, | ||
uiSchema, | ||
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 ( | ||
<Form.Input | ||
key={id} | ||
id={id} | ||
type="url" | ||
label={displayLabel ? label || schema.title : false} | ||
required={required} | ||
autoFocus={autofocus} | ||
disabled={disabled || readonly} | ||
name={name} | ||
{...semanticProps} | ||
value={value || value === 0 ? value : ""} | ||
onChange={_onChange} | ||
onBlur={_onBlur} | ||
onFocus={_onFocus} | ||
/> | ||
); | ||
} | ||
|
||
URLWidget.defaultProps = { | ||
options: { | ||
semantic: { | ||
fluid: true, | ||
inverted: false, | ||
}, | ||
}, | ||
}; | ||
|
||
export default URLWidget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './URLWidget'; | ||
export * from './URLWidget'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.