Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cgendreau committed Apr 12, 2021
2 parents 62604c9 + 9cc25bb commit 0b9145e
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 166 deletions.
22 changes: 10 additions & 12 deletions packages/common-ui/lib/formik-connected/CheckBoxField.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { FastField, FieldProps } from "formik";
import React from "react";
import React, { ChangeEvent } from "react";
import { FieldWrapper, LabelWrapperParams } from "./FieldWrapper";
import { OnFormikSubmit } from "./safeSubmit";

export interface CheckBoxProps extends LabelWrapperParams {
onCheckBoxClick?: (e) => void;
onCheckBoxClick?: OnFormikSubmit<ChangeEvent<HTMLInputElement>>;
disabled?: boolean;
}

const checkboxProps = {
style: {
display: "block",
height: "20px",
margin: "auto",
marginLeft: "15px",
width: "20px"
},
type: "checkbox"
Expand All @@ -32,21 +33,18 @@ export function CheckBoxField(props: CheckBoxProps) {
)}
>
<FastField name={name}>
{({
field: { value },
form: { setFieldValue, setFieldTouched }
}: FieldProps) => {
function onChange(event) {
setFieldValue(name, event.target.checked);
setFieldTouched(name);
onCheckBoxClick?.(event);
{({ field: { value }, form }: FieldProps) => {
function onChange(event, formik) {
formik.setFieldValue(name, event.target.checked);
formik.setFieldTouched(name);
onCheckBoxClick?.(event, formik);
}

return (
<input
{...checkboxProps}
checked={value || false}
onChange={onChange}
onChange={event => onChange(event, form)}
value={value || false}
disabled={disabled}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ResourceSelectFieldProps<TData extends KitsuResource>
onChange?: (
value?: PersistedResource<TData> | PersistedResource<TData>[]
) => void;
isDisabled?: boolean;
}

/** Formik-connected Dropdown select input for selecting a resource from the API. */
Expand Down
6 changes: 5 additions & 1 deletion packages/common-ui/lib/resource-select/ResourceSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export interface ResourceSelectProps<TData extends KitsuResource> {

/** Special dropdown options that can fetch an async value e.g. by creating a resource in a modal. */
asyncOptions?: AsyncOption<TData>[];

isDisabled?: boolean;
}

/**
Expand Down Expand Up @@ -78,7 +80,8 @@ export function ResourceSelect<TData extends KitsuResource>({
sort,
styles,
value,
asyncOptions
asyncOptions,
isDisabled
}: ResourceSelectProps<TData>) {
const { apiClient } = useContext(ApiClientContext);
const { formatMessage } = useIntl();
Expand Down Expand Up @@ -209,6 +212,7 @@ export function ResourceSelect<TData extends KitsuResource>({
MultiValue: SortableMultiValue
}}
distance={4}
isDisabled={isDisabled}
/>
);
}
Expand Down
Loading

0 comments on commit 0b9145e

Please sign in to comment.