Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semantic-ui: add submit button, email, url, date widgets #2224

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions packages/semantic-ui/src/DateTimeWidget/DateTimeWidget.js
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;
2 changes: 2 additions & 0 deletions packages/semantic-ui/src/DateTimeWidget/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './DateTimeWidget';
export * from './DateTimeWidget';
63 changes: 63 additions & 0 deletions packages/semantic-ui/src/DateWidget/DateWidget.js
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;
2 changes: 2 additions & 0 deletions packages/semantic-ui/src/DateWidget/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './DateWidget';
export * from './DateWidget';
82 changes: 82 additions & 0 deletions packages/semantic-ui/src/EmailWidget/EmailWidget.js
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;
2 changes: 2 additions & 0 deletions packages/semantic-ui/src/EmailWidget/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './EmailWidget';
export * from './EmailWidget';
4 changes: 4 additions & 0 deletions packages/semantic-ui/src/SubmitButton/SubmitButton.js
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 />);

2 changes: 2 additions & 0 deletions packages/semantic-ui/src/SubmitButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './SubmitButton';
export * from './SubmitButton';
3 changes: 3 additions & 0 deletions packages/semantic-ui/src/Theme/Theme.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import { utils } from '@rjsf/core';
import { Form as SuiForm } from "semantic-ui-react";
import SubmitButton from '../SubmitButton';
import ArrayFieldTemplate from "../ArrayFieldTemplate";
import ErrorList from "../ErrorList";
import Fields from "../Fields";
Expand All @@ -17,6 +19,7 @@ const Theme = {
ObjectFieldTemplate,
tagName: SuiForm,
widgets: { ...widgets, ...Widgets },
children: React.createElement(SubmitButton)
};

export default Theme;
64 changes: 64 additions & 0 deletions packages/semantic-ui/src/URLWidget/URLWidget.js
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;
2 changes: 2 additions & 0 deletions packages/semantic-ui/src/URLWidget/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './URLWidget';
export * from './URLWidget';
9 changes: 8 additions & 1 deletion packages/semantic-ui/src/Widgets/Widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ import SelectWidget from "../SelectWidget/SelectWidget";
import TextareaWidget from "../TextareaWidget/TextareaWidget";
import TextWidget from "../TextWidget/TextWidget";
import UpDownWidget from "../UpDownWidget/UpDownWidget";

import DateWidget from "../DateWidget/DateWidget";
import DateTimeWidget from "../DateTimeWidget/DateTimeWidget";
import EmailWidget from "../EmailWidget/EmailWidget";
import URLWidget from "../URLWidget/URLWidget";
export default {
CheckboxWidget,
CheckboxesWidget,
DateWidget,
DateTimeWidget,
PasswordWidget,
EmailWidget,
URLWidget,
RadioWidget,
RangeWidget,
SelectWidget,
Expand Down
45 changes: 21 additions & 24 deletions packages/semantic-ui/test/__snapshots__/Array.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ exports[`array fields array 1`] = `
</div>
</div>
</div>
<div>
<button
className="btn btn-info"
type="submit"
>
Submit
</button>
</div>
<button
className="ui primary button"
onClick={[Function]}
type="submit"
>
Submit
</button>
</form>
`;

Expand Down Expand Up @@ -155,14 +154,13 @@ exports[`array fields checkboxes 1`] = `
</div>
</div>
</div>
<div>
<button
className="btn btn-info"
type="submit"
>
Submit
</button>
</div>
<button
className="ui primary button"
onClick={[Function]}
type="submit"
>
Submit
</button>
</form>
`;

Expand Down Expand Up @@ -272,13 +270,12 @@ exports[`array fields fixed array 1`] = `
</div>
</div>
</div>
<div>
<button
className="btn btn-info"
type="submit"
>
Submit
</button>
</div>
<button
className="ui primary button"
onClick={[Function]}
type="submit"
>
Submit
</button>
</form>
`;
Loading