Skip to content

Commit

Permalink
feat(web/input): allowCancel option
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed Jan 11, 2023
1 parent 9a3cff8 commit 9a92729
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 7 additions & 2 deletions resource/interface/client/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ local input
---@field step? number
---@field description? string

---@class InputDialogOptionsProps
---@field allowCancel? boolean

---@param heading string
---@param rows string[] | InputDialogRowProps[]
---@param options InputDialogOptionsProps[]
---@return string[] | number[] | boolean[] | nil
function lib.inputDialog(heading, rows)
function lib.inputDialog(heading, rows, options)
if input then return end
input = promise.new()

Expand All @@ -35,7 +39,8 @@ function lib.inputDialog(heading, rows)
action = 'openDialog',
data = {
heading = heading,
rows = rows
rows = rows,
options = options
}
})

Expand Down
12 changes: 11 additions & 1 deletion web/src/features/dialog/InputDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import ColorField from './components/fields/color';
export interface InputProps {
heading: string;
rows: Array<IInput | ICheckbox | ISelect | INumber | ISlider | IColorInput>;
options?: {
allowCancel?: boolean;
};
}

export type FormValues = {
Expand Down Expand Up @@ -80,6 +83,7 @@ const InputDialog: React.FC = () => {
opened={visible}
onClose={handleClose}
centered
closeOnEscape={fields.options?.allowCancel !== false}
closeOnClickOutside={false}
size="xs"
styles={{ title: { textAlign: 'center', width: '100%', fontSize: 18 } }}
Expand Down Expand Up @@ -117,7 +121,13 @@ const InputDialog: React.FC = () => {
);
})}
<Group position="right" spacing={10}>
<Button uppercase variant="default" onClick={handleClose} mr={3}>
<Button
uppercase
variant="default"
onClick={handleClose}
mr={3}
disabled={fields.options?.allowCancel === false}
>
{locale.ui.cancel}
</Button>
<Button uppercase variant="light" type="submit">
Expand Down

0 comments on commit 9a92729

Please sign in to comment.