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

feat(organizations): add theming/story for Mantine TextInput TASK-1378 #5424

Merged
merged 29 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3105f47
refactor(frontend): add Mantine Component Library
Akuukis Dec 11, 2024
453f2c1
wip(frontend): example mantine usage
Akuukis Dec 11, 2024
15b3557
refactor(theme): rename theme
Akuukis Dec 12, 2024
d782e38
refactor(theme): style Button
Akuukis Dec 12, 2024
eca5c85
wip: TODO before merge
Akuukis Dec 12, 2024
cde2874
refactor(theme): extend Button with tooltip
Akuukis Dec 12, 2024
7142d55
Merge branch 'main' into kalvis/mantine-setup
magicznyleszek Dec 16, 2024
511b407
Fix Checkbox component misaligned element caused by Mantine's CSS Reset
magicznyleszek Dec 16, 2024
27e8f95
setup Storybook for Mantine by following official guide
magicznyleszek Dec 18, 2024
2df7caa
improve gray color comments from Mantine theme
magicznyleszek Dec 18, 2024
717f080
Merge branch 'main' into kalvis/mantine-setup
magicznyleszek Dec 18, 2024
b5695da
Merge branch 'main' into kalvis/mantine-setup
magicznyleszek Dec 19, 2024
af2517c
Merge branch 'main' of github.com:kobotoolbox/kpi into kalvis/mantine…
magicznyleszek Dec 30, 2024
29c9092
Merge branch 'kalvis/mantine-setup' of github.com:kobotoolbox/kpi int…
magicznyleszek Dec 30, 2024
9293760
Merge branch 'main' into kalvis/mantine-setup
magicznyleszek Jan 4, 2025
d4dea03
refactor(SimpleTable): drop BEM, use Mantine TASK-1377 (#5366)
magicznyleszek Jan 6, 2025
bafb0be
Merge branch 'main' into kalvis/mantine-setup
magicznyleszek Jan 6, 2025
3e62d24
feat(organizations): add mantine menu theme/story TASK-1382 (#5410)
jamesrkiger Jan 8, 2025
4691dde
Remove todo comment
jamesrkiger Jan 14, 2025
4df19e6
Merge branch 'main' of github.com:kobotoolbox/kpi into task-1378-mant…
RuthShryock Jan 15, 2025
fc6fe0c
Merge branch 'main' of github.com:kobotoolbox/kpi into task-1378-mant…
RuthShryock Jan 16, 2025
047844e
added wrapped mantine TextInput componenet with styling and storybook
RuthShryock Jan 16, 2025
3aa2883
add setValue
RuthShryock Jan 16, 2025
54f1976
Resolve merge conflicts
jamesrkiger Jan 22, 2025
11f4c62
Move theming and configuration to Input and InputWrapper components
jamesrkiger Jan 22, 2025
4d9a78b
Remove wrapped TextInput, add theming through InputBase and css module
jamesrkiger Jan 28, 2025
9073cb0
Resolve merge conflicts
jamesrkiger Jan 28, 2025
b3c11a1
Update jsapp/js/theme/kobo/InputBase.ts
jamesrkiger Jan 29, 2025
985bf49
Delete outdated input wrapper theming
jamesrkiger Jan 29, 2025
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
114 changes: 114 additions & 0 deletions jsapp/js/components/common/textInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import type {ComponentStory, ComponentMeta} from '@storybook/react';
import {TextInput} from './textInput';
import {IconNames} from 'jsapp/fonts/k-icons';
import Icon from './icon';

export default {
title: 'common/TextInput',
component: TextInput,
argTypes: {
label: {
description: 'Appears above the input',
control: 'text',
},
placeholder: {
description: 'Placeholder text for the input',
control: 'text',
type: 'string',
},
value: {
description: 'Current value of the input',
control: 'text',
},
onChange: {
description: 'Input value change callback',
},
size: {
description:
'Changes the size of the component (similar sizing as Button)',
defaultValue: {summary: 'lg'},
options: ['sm', 'md', 'lg'],
control: {type: 'radio'},
},
leftSection: {
description: 'Appears inside the input, on the beginning.',
options: Object.keys(IconNames),
mapping: Object.keys(IconNames)
.map(
(key) =>
[key, <Icon name={key as IconNames} color='storm' />] as const
)
.reduce((o, [k, v]) => {
return {...o, [k]: v};
}, {}),
control: {type: 'select'},
},
rightSection: {
description:
'Appears inside the input, on the end. Is replaced by "alert" icon if there are any errors.',
options: Object.keys(IconNames),
mapping: Object.keys(IconNames)
.map(
(key) =>
[key, <Icon name={key as IconNames} color='storm' />] as const
)
.reduce((o, [k, v]) => {
return {...o, [k]: v};
}, {}),
control: {type: 'select'},
},
disabled: {
description: 'Disables the input',
control: 'boolean',
},
required: {
description: 'Marks the input as required',
control: 'boolean',
},
error: {
description: 'Error message or state for the input',
control: 'text',
},
withAsterisk: {
description: 'Displays an asterisk if the input is required',
control: 'boolean',
},
},
} as ComponentMeta<typeof TextInput>;

const Template: ComponentStory<typeof TextInput> = (args) => (
<TextInput {...args} />
);

export const Primary = Template.bind({});
Primary.args = {
label: 'Default Text Input',
placeholder: 'Enter text...',
size: 'md',
};

export const Disabled = Template.bind({});
Disabled.args = {
label: 'Disabled Input',
placeholder: 'You cannot type here',
size: 'md',
disabled: true,
};

export const WithError = Template.bind({});
WithError.args = {
label: 'Email',
placeholder: 'Enter your email',
error: 'Invalid email address',
size: 'md',
};

export const WithIcon = Template.bind({});
WithIcon.args = {
label: 'Required Input',
placeholder: 'This field is required',
required: true,
withAsterisk: true,
leftSection: <Icon name='user' color='storm' />,
size: 'md',
};
61 changes: 61 additions & 0 deletions jsapp/js/components/common/textInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, {useEffect, useState} from 'react';
import {
TextInput as MantineTextInput,
type TextInputProps,
} from '@mantine/core';
import Icon from './icon';

interface CustomTextInputProps extends Omit<TextInputProps, 'onChange'> {
onChange?: (newValue: string) => void;
renderFocused?: boolean;
}

export const TextInput: React.FC<CustomTextInputProps> = (props) => {
const {error, disabled, rightSection, ...rest} = props;
const [value, setValue] = useState(props.value || '');
const inputReference: React.MutableRefObject<null | HTMLInputElement> =
React.createRef();

useEffect(() => {
if (props.renderFocused) {
inputReference.current?.focus();
}
}, []);

const onValueChange = (newValue: string) => {
if (props.readOnly || !props.onChange) {
return;
}
setValue(newValue);
props.onChange(newValue);
};

return (
<MantineTextInput
{...rest}
value={value}
onInput={(evt: React.ChangeEvent<HTMLInputElement>) => {
onValueChange(evt.currentTarget.value);
}}
onChange={() => false}
ref={inputReference}
error={error}
disabled={disabled}
rightSection={
error ? <Icon name='alert' color='mid-red' /> : rightSection
}
styles={(theme) => {
return {
input: {
borderColor: disabled
? theme.colors.gray[2]
: error
? theme.colors.red[7]
: theme.colors.gray[6],
color: disabled ? theme.colors.gray[2] : theme.colors.gray[1],
},
};
}}
/>
);
};
18 changes: 18 additions & 0 deletions jsapp/js/theme/kobo/TextInput.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.label {
color: var(--mantine-color-gray-1);
font-size: 12px;
line-height: 20px;
margin-bottom: 3px;
}

.input:focus-visible {
box-shadow: 0 0 0 2px var(--mantine-color-blue-7);
}

.input::placeholder {
color: var(--mantine-color-gray-3);
}

.input:disabled {
background-color: var(--mantine-color-gray-7);
}
11 changes: 11 additions & 0 deletions jsapp/js/theme/kobo/TextInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {TextInput} from '@mantine/core';
import classes from './TextInput.module.css';

export const TextInputThemeKobo = TextInput.extend({
classNames: classes,
defaultProps: {
placeholder: 'Enter text',
size: 'sm',
radius: 'md',
},
});
2 changes: 2 additions & 0 deletions jsapp/js/theme/kobo/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {createTheme, rem} from '@mantine/core';
import {ButtonThemeKobo} from './Button';
import {TableThemeKobo} from './Table';
import {TextInputThemeKobo} from './TextInput';
import {TooltipThemeKobo} from './Tooltip';
import {MenuThemeKobo} from './menu';

Expand Down Expand Up @@ -91,5 +92,6 @@ export const themeKobo = createTheme({
Menu: MenuThemeKobo,
Tooltip: TooltipThemeKobo,
Table: TableThemeKobo,
TextInput: TextInputThemeKobo,
},
});
Loading