Skip to content

Commit

Permalink
Separate components at same level for more redeability and avoid re-r…
Browse files Browse the repository at this point in the history
…ender because inputProps object
  • Loading branch information
anagperal committed Jul 4, 2024
1 parent 64fc4ad commit 3031a13
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/webapp/components/avatar-card/AvatarCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const AvatarCard: React.FC<AvatarCardProps> = React.memo(
<AvatarContainer $size={avatarSize}>
<Avatar alt={alt} src={src} />
</AvatarContainer>

<StyledCardContent>{children}</StyledCardContent>
</StyledCard>
);
Expand Down
8 changes: 6 additions & 2 deletions src/webapp/components/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from "react";
import React, { useCallback, useMemo } from "react";
import { Checkbox as MUICheckbox, InputLabel, FormHelperText } from "@material-ui/core";
import styled from "styled-components";

Expand Down Expand Up @@ -32,6 +32,8 @@ export const Checkbox: React.FC<CheckboxProps> = React.memo(
[onChange]
);

const inputProps = useMemo(() => ({ "aria-label": label || `${id}-label` }), [id, label]);

return (
<Container>
<CheckboxWrapper>
Expand All @@ -42,12 +44,14 @@ export const Checkbox: React.FC<CheckboxProps> = React.memo(
onChange={handleChange}
disabled={disabled}
size="small"
inputProps={{ "aria-label": label || `${id}-label` }}
inputProps={inputProps}
/>

<Label htmlFor={id} disabled={disabled}>
{label}
</Label>
</CheckboxWrapper>

<StyledFormHelperText id={`${id}-helper-text`}>{helperText}</StyledFormHelperText>
</Container>
);
Expand Down
1 change: 1 addition & 0 deletions src/webapp/components/date-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const DatePicker: React.FC<DatePickerProps> = React.memo(
{label}
</Label>
)}

<LocalizationProvider dateAdapter={AdapterDateFns}>
<StyledDatePicker
value={value}
Expand Down
4 changes: 4 additions & 0 deletions src/webapp/components/form/FormLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ export const FormLayout: React.FC<FormLayoutProps> = React.memo(
{title && <Title>{title}</Title>}
{subtitle && <Subtitle>{subtitle}</Subtitle>}
</TitleContainer>

<RequiredText>{i18n.t("Indicates required")}</RequiredText>
</Header>

<Content>{children}</Content>

<Footer>
<Separator margin="12px" />

<ButtonsFooter>
<Button onClick={onSave}>{saveLabel || i18n.t("Save")}</Button>
{onCancel && (
Expand Down
3 changes: 3 additions & 0 deletions src/webapp/components/form/FormSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ export const FormSection: React.FC<FormSectionProps> = React.memo(
return (
<FormSectionContainer>
{hasSeparator && <Separator margin="12px" />}

<Container direction={direction}>
{title && (
<TitleContainer direction={direction}>
<RequiredText className={required ? "required" : ""}>
{title}
</RequiredText>

{onClickInfo && (
<IconButton icon={<IconInfo24 />} onClick={onClickInfo} />
)}
</TitleContainer>
)}

<FormContainer fulWidth={!title}>{children}</FormContainer>
</Container>
</FormSectionContainer>
Expand Down
1 change: 1 addition & 0 deletions src/webapp/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const Layout: React.FC<LayoutProps> = React.memo(
<Button onClick={() => setSideBarOpen(!sideBarOpen)} startIcon={<Menu />} />
</OpenMenuContainer>
) : null}

<MainContent
sideBarOpen={sideBarOpen}
toggleSideBar={setSideBarOpen}
Expand Down
4 changes: 4 additions & 0 deletions src/webapp/components/layout/header-bar/HeaderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ export const HeaderBar: React.FC<HeaderBarProps> = React.memo(({ name }) => {
return (
<Container>
<FlagBar color="red" />

<FlagBar color="black" />

<FlagBar color="orange" />

<AppName>{name}</AppName>

<StyledHeaderBar className="app-header" appName="ZEBRA App" />
</Container>
);
Expand Down
3 changes: 3 additions & 0 deletions src/webapp/components/layout/main-content/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ export const MainContent: React.FC<MainContentProps> = React.memo(
toggleSideBar={toggleSideBar}
showCreateEvent={showCreateEvent}
/>

<Main>
{title && <Title>{title}</Title>}

{subtitle && <SubTitle>{subtitle}</SubTitle>}

<PageContent>{children}</PageContent>
</Main>
</Container>
Expand Down
1 change: 1 addition & 0 deletions src/webapp/components/notice-box/NoticeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const NoticeBox: React.FC<NoticeBoxProps> = React.memo(({ title, children
<IconInfo24 />
{title}
</TitleContainer>

<Content>{children}</Content>
</Container>
);
Expand Down
3 changes: 3 additions & 0 deletions src/webapp/components/profile-modal/ProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ export const ProfileModal: React.FC<ProfileModalProps> = React.memo(
>
<StyledCard variant="outlined">
<Name>{name}</Name>

<Content>
<AvatarContainer>
<Avatar alt={alt} src={src} />
</AvatarContainer>

<StyledCardContent>{children}</StyledCardContent>
</Content>

<Footer>
<Button onClick={onClose}>{i18n.t("Close")}</Button>
</Footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function RadioButtonsGroup<Value extends string>({
{label}
</Label>
)}

<StyledRadioGroup
aria-label={id}
name={id}
Expand All @@ -56,6 +57,7 @@ export function RadioButtonsGroup<Value extends string>({
/>
))}
</StyledRadioGroup>

<StyledFormHelperText id={`${id}-helper-text`} error={error && !!errorText}>
{error && !!errorText ? errorText : helperText}
</StyledFormHelperText>
Expand Down
15 changes: 9 additions & 6 deletions src/webapp/components/search-input/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ type SearchInputProps = {
disabled?: boolean;
};

const INPUT_PROPS = { "aria-label": "search" };

export const SearchInput: React.FC<SearchInputProps> = React.memo(
({ value, onChange, placeholder = "", disabled = false }) => {
const [stateValue, updateStateValue] = useState(value);

useEffect(() => updateStateValue(value), [value]);

// eslint-disable-next-line react-hooks/exhaustive-deps
const onChangeDebounced = useCallback(
debounce((value: string) => {
if (onChange) onChange(value);
}, 400),
const onChangeDebounced = React.useMemo(
() =>
debounce((value: string) => {
if (onChange) onChange(value);
}, 400),
[onChange]
);

Expand All @@ -44,6 +46,7 @@ export const SearchInput: React.FC<SearchInputProps> = React.memo(
<IconContainer $disabled={disabled}>
<IconSearch24 />
</IconContainer>

<StyledTextField
onChange={handleChange}
placeholder={placeholder || i18n.t("Search")}
Expand All @@ -52,7 +55,7 @@ export const SearchInput: React.FC<SearchInputProps> = React.memo(
onKeyDown={handleKeydown}
disabled={disabled}
variant="outlined"
inputProps={{ "aria-label": "search" }}
inputProps={INPUT_PROPS}
/>
</Container>
);
Expand Down
4 changes: 4 additions & 0 deletions src/webapp/components/section/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ export const Section: React.FC<SectionProps> = React.memo(
return (
<SectionContainer $hasSeparator={hasSeparator}>
{hasSeparator && <Separator />}

<Header>
<TitleContainer>
{title ? <Title $titleVariant={titleVariant}>{title}</Title> : null}

{lastUpdated ? (
<LastUpdatedContainer>
<LastUpdatedTitle>
Expand All @@ -37,8 +39,10 @@ export const Section: React.FC<SectionProps> = React.memo(
</LastUpdatedContainer>
) : null}
</TitleContainer>

{headerButtom ? <div>{headerButtom}</div> : null}
</Header>

<Content>{children}</Content>
</SectionContainer>
);
Expand Down
2 changes: 2 additions & 0 deletions src/webapp/components/selector/MultipleSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function MultipleSelector<Value extends string>({
{label}
</Label>
)}

<StyledSelect
labelId={label || `${id}-label`}
id={id}
Expand Down Expand Up @@ -95,6 +96,7 @@ export function MultipleSelector<Value extends string>({
</MenuItem>
))}
</StyledSelect>

<StyledFormHelperText id={`${id}-helper-text`} error={error && !!errorText}>
{error && !!errorText ? errorText : helperText}
</StyledFormHelperText>
Expand Down
2 changes: 2 additions & 0 deletions src/webapp/components/selector/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function Selector<Value extends string>({
{label}
</Label>
)}

<StyledSelect
labelId={label || `${id}-label`}
id={id}
Expand All @@ -72,6 +73,7 @@ export function Selector<Value extends string>({
</MenuItem>
))}
</StyledSelect>

<StyledFormHelperText id={`${id}-helper-text`} error={error && !!errorText}>
{error && !!errorText ? errorText : helperText}
</StyledFormHelperText>
Expand Down
3 changes: 3 additions & 0 deletions src/webapp/components/stats-card/StatsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ export const StatsCard: React.FC<StatsCardProps> = React.memo(
<StyledCard $error={error}>
<StyledCardContent>
<Stat color={color}>{`${stat}${isPercentage ? " %" : ""}`}</Stat>

<PreTitle>{pretitle}</PreTitle>

<Title>{title}</Title>

<SubTitle>{subtitle}</SubTitle>
</StyledCardContent>
</StyledCard>
Expand Down
2 changes: 2 additions & 0 deletions src/webapp/components/text-input/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const TextArea: React.FC<TextAreaProps> = React.memo(
{label}
</Label>
)}

<StyledTextareaAutosize
id={id}
aria-label={label || `${id}-label`}
Expand All @@ -49,6 +50,7 @@ export const TextArea: React.FC<TextAreaProps> = React.memo(
disabled={disabled}
$hasError={error}
/>

<StyledFormHelperText id={`${id}-helper-text`} error={error && !!errorText}>
{error && !!errorText ? errorText : helperText}
</StyledFormHelperText>
Expand Down
1 change: 1 addition & 0 deletions src/webapp/components/text-input/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const TextInput: React.FC<TextInputProps> = React.memo(
{label}
</Label>
)}

<StyledTextField
id={id}
value={value}
Expand Down

0 comments on commit 3031a13

Please sign in to comment.