Skip to content
Open
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
34 changes: 34 additions & 0 deletions devbench/src/component/modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,40 @@ export function ModalTest() {
return props;
});

// Radio element example. Toggle `useRadio` to preview the new `radio`
// input type (single-selection group, value is the chosen option).
const useRadio = true;
const radioElements = [
{
type: 'text',
name: 'fullName',
placeholder: 'Full Name',
amount: 1
},
{
type: 'radio',
name: 'plan',
placeholder: 'Choose a plan',
options: ['Free', 'Pro', 'Enterprise'],
amount: 1
}
];

if (useRadio) {
return (
<Modal
title="Sign up"
Id="radio-modal"
className="testmodal"
theme={'Crimson'}
type="form"
elements={radioElements}
onSubmit={(data) => console.log('submitted', data)}
onChange={(data) => console.log(data)}
/>
);
}

return (
<Modal
title="Register"
Expand Down
16 changes: 16 additions & 0 deletions src/components/modal/dependencies/elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@
"requires-options": false,
"r-variant": true
},
{
"element": "radio",
"tag": "input",
"tag-type": "radio",
"default-class": "modal-radio",
"aria": {
"role": "radiogroup",
"aria-label": ""
},
"supports-placeholder": true,
"supports_type": true,
"supports_autocomplete": false,
"is_custom": false,
"requires-options": true,
"r-variant": true
},
{
"element": "file",
"tag": "DyvixFile",
Expand Down
24 changes: 24 additions & 0 deletions src/components/modal/dependencies/style/elements.css
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,30 @@
gap: 0.5rem;
cursor: pointer;
}
.modal-radio-group {
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 0.7rem;
width: 100%;
align-items: center;
}
.modal-radio-legend {
font-size: 1rem;
font-weight: 500;
opacity: 0.85;
margin-right: 0.2rem;
}
.modal-radio-label {
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
}
.modal-radio {
accent-color: #0ea5e9;
cursor: pointer;
}
.modal-textarea {
max-height: 70px;
min-height: 35px;
Expand Down
42 changes: 36 additions & 6 deletions src/components/modal/modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import DyvixButton from '../button/button';
import DyvixFile from '../file/file';
import DyvixInput from '../input/input';
import { values } from 'idb-keyval';
import DyvixLabel from '../label/label';

export const validType = typesData.map((e) => e.type);
export const validRules = validationData.map((e) => e.preset);
Expand Down Expand Up @@ -388,12 +389,11 @@ function Modal({
ariaAttributes['aria-required'] =
ariaProps['aria-required'];
}
const options =
Tag === 'select' || elementDef.tag === 'DyvixSelect'
? Array.isArray(field.options[0])
? field.options[j]
: field.options
: [];
const options = elementDef['requires-options']
? Array.isArray(field.options[0])
? field.options[j]
: field.options
: [];
const fieldError = errors[name];
const ErrorId =
`${id && id !== '!/' ? id : field.placeholder[j]}-error`
Expand Down Expand Up @@ -474,6 +474,36 @@ function Modal({
</option>
))}
</Tag>
) : field.type === 'radio' ? (
<div
key={j}
className="modal-radio-group"
role="radiogroup"
aria-label={field.placeholder?.[j]}
style={themeTextStyle}
>
{field.placeholder?.[j] &&
field.placeholder[j] !== '!/' && (
<DyvixLabel className="modal-radio-legend" animation={null} theme={theme}>
{field.placeholder[j]}
</DyvixLabel>
)}
{options.map((opt, index) => (
<DyvixLabel key={index} className="modal-radio-label" animation={null} theme={theme}>
<input
type="radio"
className="modal-radio"
name={name}
value={opt}
checked={data[name] === opt}
onChange={() => handleInputChange(name, opt)}
{...(id &&
id !== '!/' && { id: `${id}-${index}` })}
/>
{opt}
</DyvixLabel>
))}
</div>
) : field.type === 'checkbox' ? (
<label
key={j}
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const DYVIX_MODAL_ELEMENT = {
D_SELECT: 'd-select',
AUTOCOMPLETE: 'autocomplete',
CHECKBOX: 'checkbox',
RADIO: 'radio',
FILE: 'file'
};
export const DYVIX_MODAL_PRESET = {
Expand Down