Skip to content

Commit

Permalink
Merge pull request #270 from notifirehq/rld-95-add-onchange-event-for…
Browse files Browse the repository at this point in the history
…-all-components

✨ Add onChange and onClick events to components
  • Loading branch information
scopsy committed Feb 17, 2022
2 parents 2cad1ee + 084cca0 commit 32934e2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 36 deletions.
5 changes: 3 additions & 2 deletions apps/web/src/design-system/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ interface IButtonProps extends JSX.ElementChildrenAttribute {
size?: 'md' | 'lg';
variant?: 'outline' | 'filled';
disabled?: boolean;
onClick?: () => void;
}

/**
* Button component
*
*/
export function Button({ loading, children, size = 'md', disabled = false, ...props }: IButtonProps) {
export function Button({ loading, children, size = 'md', disabled = false, onClick, ...props }: IButtonProps) {
const { classes } = useStyles(disabled);
const defaultDesign = { radius: 'md', classNames: classes } as SharedButtonProps;

return (
<MantineButton {...defaultDesign} disabled={disabled} size={size} loading={loading} {...props}>
<MantineButton {...defaultDesign} onClick={onClick} disabled={disabled} size={size} loading={loading} {...props}>
{children}
</MantineButton>
);
Expand Down
15 changes: 12 additions & 3 deletions apps/web/src/design-system/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import React from 'react';
import React, { ChangeEvent } from 'react';
import { Checkbox as MantineCheckbox } from '@mantine/core';
import useStyles from './Checkbox.styles';

interface CheckboxProps {
checked?: boolean;
disabled?: boolean;
label?: string;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
}

/**
* Checkbox Component
*
*/
export function Checkbox({ label = 'Default Checkbox', checked, disabled = false, ...props }: CheckboxProps) {
export function Checkbox({ label = 'Default Checkbox', checked, onChange, disabled = false, ...props }: CheckboxProps) {
const { classes } = useStyles();

return (
<MantineCheckbox classNames={classes} label={label} disabled={disabled} size="sm" checked={checked} {...props} />
<MantineCheckbox
classNames={classes}
label={label}
onChange={onChange}
disabled={disabled}
size="sm"
checked={checked}
{...props}
/>
);
}
7 changes: 4 additions & 3 deletions apps/web/src/design-system/input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ChangeEvent } from 'react';
import { TextInputProps, TextInput as MantineTextInput } from '@mantine/core';
import { inputStyles } from '../config/inputs.styles';

Expand All @@ -8,14 +8,15 @@ interface IInputProps {
placeholder?: string;
value?: string;
description?: string;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
}

/**
* Input component
*
*/
export function Input({ value, ...props }: IInputProps) {
export function Input({ value, onChange, ...props }: IInputProps) {
const defaultDesign = { radius: 'md', size: 'md', styles: inputStyles } as TextInputProps;

return <MantineTextInput {...defaultDesign} defaultValue={value} {...props} />;
return <MantineTextInput {...defaultDesign} onChange={onChange} defaultValue={value} {...props} />;
}
56 changes: 32 additions & 24 deletions apps/web/src/design-system/select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,45 @@ import { inputStyles } from '../config/inputs.styles';

interface ISelectProps {
data: (string | { value: string; label?: string })[];
onChange?: (value: string[] | string | null) => void;
label?: React.ReactNode;
placeholder?: string;
description?: string;
searchable?: boolean;
type?: 'multiselect' | 'select';
}

/**
* Select component
*
*/
export function Select({ data, type = 'select', searchable = false, onChange, ...props }: ISelectProps) {
const { classes } = useStyles();
const searchableSelectProps = searchable ? { searchable, nothingFound: 'Nothing Found', allowDeselect: true } : {};
const defaultDesign = {
radius: 'md',
size: 'md',
rightSection: <ChevronIcon />,
rightSectionWidth: 60,
styles: inputStyles,
classNames: classes,
} as InputBaseProps;
const multiselect = type === 'multiselect';

return multiselect ? (
<MantineMultiSelect
onChange={onChange}
{...defaultDesign}
{...searchableSelectProps}
data={data}
valueComponent={Value}
{...props}
/>
) : (
<MantineSelect {...defaultDesign} {...searchableSelectProps} onChange={onChange} data={data} {...props} />
);
}

function Value({ label, onRemove }: MultiSelectValueProps) {
const theme = useMantineTheme();
const dark = theme.colorScheme === 'dark';
Expand Down Expand Up @@ -49,27 +81,3 @@ function Value({ label, onRemove }: MultiSelectValueProps) {
</Box>
);
}

/**
* Select component
*
*/
export function Select({ data, type = 'select', searchable = false, ...props }: ISelectProps) {
const { classes } = useStyles();
const searchableSelectProps = searchable ? { searchable, nothingFound: 'Nothing Found', allowDeselect: true } : {};
const defaultDesign = {
radius: 'md',
size: 'md',
rightSection: <ChevronIcon />,
rightSectionWidth: 60,
styles: inputStyles,
classNames: classes,
} as InputBaseProps;
const multiselect = type === 'multiselect';

return multiselect ? (
<MantineMultiSelect {...defaultDesign} {...searchableSelectProps} data={data} valueComponent={Value} {...props} />
) : (
<MantineSelect {...defaultDesign} {...searchableSelectProps} data={data} {...props} />
);
}
8 changes: 4 additions & 4 deletions apps/web/src/design-system/switch/Switch.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React from 'react';
import React, { ChangeEvent } from 'react';
import { Switch as MantineSwitch, SwitchProps } from '@mantine/core';
import useStyles from './Switch.styles';

interface ISwitchProps {
label?: React.ReactNode;
checked?: boolean;
onChange?: () => void;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
}

/**
* Switch component
*
*/
export function Switch({ ...props }: ISwitchProps) {
export function Switch({ onChange, ...props }: ISwitchProps) {
const { classes } = useStyles();
const defaultDesign = { radius: 'xl', size: 'md', classNames: classes } as SwitchProps;

return <MantineSwitch {...defaultDesign} {...props} />;
return <MantineSwitch onChange={onChange} {...defaultDesign} {...props} />;
}

1 comment on commit 32934e2

@vercel
Copy link

@vercel vercel bot commented on 32934e2 Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

storybook – ./

notifire.vercel.app
storybook-relayed.vercel.app
storybook-git-master-relayed.vercel.app

Please sign in to comment.