Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"rollup-plugin-typescript2": "^0.36.0",
"storybook": "^8.2.8",
"style-loader": "^3.3.1",
"styled-components": "^6.1.19",
"styled-components": "^6.4.1",
"typescript": "^4.8.4"
},
"lint-staged": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ const MyCustomComponent: TCustomComponent<MyCustomSchema> = (props: TCustomCompo
const {
error,
id,
onBlur,
onChange,
schema: { displayTitle, validation },
value,
...otherProps
} = props;

const {
Expand Down Expand Up @@ -81,10 +81,10 @@ const MyCustomComponent: TCustomComponent<MyCustomSchema> = (props: TCustomCompo
label={displayTitle}
id={id}
errorMessage={error?.message}
onBlur={onBlur}
onChange={handleDispatchEvent}
onClick={handleRemoveEvent}
value={value || ""}
{...otherProps}
/>
);
};
Expand Down
13 changes: 6 additions & 7 deletions src/components/custom/filter/filter-checkbox/filter-checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useState } from "react";
import { useFormContext } from "react-hook-form";
import useDeepCompareEffect from "use-deep-compare-effect";
import * as Yup from "yup";
import { TestHelper } from "../../../../utils";
import { TestHelper, filterSchemaProps } from "../../../../utils";
import { useValidationConfig } from "../../../../utils/hooks";
import { Sanitize } from "../../../shared";
import { IGenericCustomFieldProps } from "../../types";
Expand All @@ -14,12 +14,11 @@ export const FilterCheckbox = (props: IGenericCustomFieldProps<IFilterCheckboxSc
// =============================================================================
// CONST, STATE, REFS
// =============================================================================
const { schema, id, value, onChange } = props;
const {
schema: { label, options, expanded, validation, ...otherSchema },
id,
value,
onChange,
} = props;
commonSchema: { label, validation },
customSchema: { clearBehavior: _clearBehavior, options, expanded, ...checkboxProps },
} = filterSchemaProps(schema);

const { setValue } = useFormContext();
const [selectedOptions, setSelectedOptions] = useState<IOption[]>(); // Current selected value state
Expand Down Expand Up @@ -79,7 +78,7 @@ export const FilterCheckbox = (props: IGenericCustomFieldProps<IFilterCheckboxSc
return (
<Filter.Checkbox
id={id}
{...otherSchema}
{...checkboxProps}
data-testid={TestHelper.generateId(id, "filter-checkbox")}
title={title}
addon={addon}
Expand Down
11 changes: 5 additions & 6 deletions src/components/custom/iframe/iframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FieldError, useFormContext } from "react-hook-form";
import styled from "styled-components";
import * as Yup from "yup";
import { useFieldEvent, useIframeMessage, useValidationConfig } from "../../../utils/hooks";
import { filterSchemaProps } from "../../../utils/prop-helper";
import { IGenericCustomFieldProps } from "../types";
import { EPostMessageEvent, IIframeSchema } from "./types";

Expand All @@ -20,12 +21,10 @@ export const Iframe = (props: IGenericCustomFieldProps<IIframeSchema>) => {
// =========================================================================
// CONST, STATE, REF
// =========================================================================
const { error, id, schema, value } = props;
const {
error,
id,
schema: { "data-testid": testId, src, validationTimeout = 2000, ...otherSchema },
value,
} = props;
customSchema: { "data-testid": testId, src, validationTimeout = 2000, ...iframeProps },
} = filterSchemaProps(schema);
const formContext = useFormContext();
const iframeRef = useRef<HTMLIFrameElement>(null);
const deferredRef = useRef<{
Expand Down Expand Up @@ -175,7 +174,7 @@ export const Iframe = (props: IGenericCustomFieldProps<IIframeSchema>) => {
// =========================================================================
return (
<FluidIframe
{...otherSchema}
{...iframeProps}
ref={iframeRef}
src={src}
id={id}
Expand Down
16 changes: 11 additions & 5 deletions src/components/custom/review/review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import isEmpty from "lodash/isEmpty";
import { useEffect, useState } from "react";
import useDeepCompareEffect from "use-deep-compare-effect";
import * as Yup from "yup";
import { AxiosApiClient } from "../../../utils";
import { AxiosApiClient, filterSchemaProps } from "../../../utils";
import { useFieldEvent, useValidationConfig } from "../../../utils/hooks";
import { Wrapper } from "../../elements/wrapper";
import { IGenericCustomElementProps } from "../types";
Expand Down Expand Up @@ -173,7 +173,10 @@ export const Review = (props: IGenericCustomElementProps<TReviewSchema>) => {
// RENDER FUNCTIONS
// =========================================================================
const renderAccordion = (schema: IReviewSchemaAccordion) => {
const { button, bottomSection, expanded = true, label, topSection, ...otherSchema } = schema;
const {
commonSchema: { label },
customSchema: { button, bottomSection, expanded = true, topSection, ...accordionProps },
} = filterSchemaProps(schema);

return (
<BoxContainer
Expand All @@ -186,7 +189,7 @@ export const Review = (props: IGenericCustomElementProps<TReviewSchema>) => {
)
}
expanded={expanded}
{...otherSchema}
{...accordionProps}
>
<CustomUneditableSection
background={false}
Expand All @@ -203,10 +206,13 @@ export const Review = (props: IGenericCustomElementProps<TReviewSchema>) => {
};

const renderBox = (schema: IReviewSchemaBox) => {
const { label, description, topSection, bottomSection, ...otherSchema } = schema;
const {
commonSchema: { label },
customSchema: { description, topSection, bottomSection, ...boxProps },
} = filterSchemaProps(schema);
return (
<UneditableSection
{...otherSchema}
{...boxProps}
id={id}
title={label}
description={description}
Expand Down
7 changes: 5 additions & 2 deletions src/components/elements/accordion/accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BoxContainer } from "@lifesg/react-design-system/box-container";
import { Button } from "@lifesg/react-design-system/button";
import { useFieldEvent } from "../../../utils/hooks";
import { filterSchemaProps } from "../../../utils/prop-helper";
import { IGenericElementProps } from "../types";
import { Wrapper } from "../wrapper";
import { Container } from "./accordion.styles";
Expand All @@ -14,15 +15,17 @@ export const Accordion = (props: IGenericElementProps<IAccordionSchema>) => {
// CONST, STATE, REF
// =============================================================================
const { schema, id } = props;
const { children, button, title, disableContentInset, ...otherSchema } = schema;
const {
customSchema: { button, children, title, disableContentInset, ...accordionProps },
} = filterSchemaProps(schema);

const { dispatchFieldEvent } = useFieldEvent();

return (
<BoxContainer
id={id}
title={typeof title === "string" ? title : <Wrapper>{title}</Wrapper>}
{...otherSchema}
{...accordionProps}
callToActionComponent={
button ? (
<Button.Default
Expand Down
10 changes: 5 additions & 5 deletions src/components/elements/divider/divider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Divider as DSDivider } from "@lifesg/react-design-system/divider";
import { TestHelper } from "../../../utils";
import { TestHelper, filterSchemaProps } from "../../../utils";
import { IGenericElementProps } from "../types";
import { IDividerSchema } from "./types";
import styled from "styled-components";
Expand All @@ -8,10 +8,10 @@ export const Divider = (props: IGenericElementProps<IDividerSchema>) => {
// =============================================================================
// CONST, STATE, REF
// =============================================================================
const { id, schema } = props;
const {
id,
schema: { verticalMargin, ...otherSchema },
} = props;
customSchema: { verticalMargin, ...dividerProps },
} = filterSchemaProps(schema);

// =============================================================================
// RENDER FUNCTIONS
Expand All @@ -21,7 +21,7 @@ export const Divider = (props: IGenericElementProps<IDividerSchema>) => {
id={id}
data-testid={TestHelper.generateId(id, "divider")}
$verticalMargin={verticalMargin}
{...otherSchema}
{...dividerProps}
/>
);
};
Expand Down
12 changes: 6 additions & 6 deletions src/components/elements/popover/popover.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PopoverInline } from "@lifesg/react-design-system/popover-v2";
import * as Icons from "@lifesg/react-icons";
import { TestHelper } from "../../../utils";
import { TestHelper, filterSchemaProps } from "../../../utils";
import { Sanitize } from "../../shared";
import { IGenericElementProps } from "../types";
import { Wrapper } from "../wrapper";
Expand All @@ -11,16 +11,16 @@ export const Popover = (props: IGenericElementProps<IPopoverSchema>) => {
// =============================================================================
// CONST, STATE, REF
// =============================================================================
const { id, schema } = props;
const {
id,
schema: {
customSchema: {
children,
className,
icon,
hint: { content: hintContent, ...hintProps },
...otherSchema
...popoverProps
},
} = props;
} = filterSchemaProps(schema);

// =============================================================================
// RENDER FUNCTIONS
Expand Down Expand Up @@ -56,7 +56,7 @@ export const Popover = (props: IGenericElementProps<IPopoverSchema>) => {
content={children && <Sanitize inline>{children}</Sanitize>}
popoverContent={renderPopoverContent()}
{...hintProps}
{...otherSchema}
{...popoverProps}
/>
);
};
13 changes: 6 additions & 7 deletions src/components/elements/tab/tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ export const Tab = (props: IGenericElementProps<ITabSchema>) => {
// =========================================================================
// CONST, STATE, REF
// =========================================================================
const {
id,
schema: { currentActiveTabId, children, ...otherTabSchema },
} = props;
const { id, schema } = props;
const { children, currentActiveTabId, fullWidthIndicatorLine } = schema;
const [currentTabIndex, setCurrentTabIndex] = useState(getCurrentTabIndex());
const { removeFieldValidationConfig } = useValidationConfig();
const { unregister } = useFormContext();
Expand Down Expand Up @@ -100,21 +98,22 @@ export const Tab = (props: IGenericElementProps<ITabSchema>) => {
// =========================================================================
return (
<DSTab
{...otherTabSchema}
id={id}
data-testid={TestHelper.generateId(id, "tab")}
currentActive={currentTabIndex}
fullWidthIndicatorLine={fullWidthIndicatorLine}
onTabClick={handleTabClick}
>
{Object.entries(children).map(([childId, childSchema]) => {
const { title, children, ...otherTabItemSchema } = childSchema;
const { children, title, width } = childSchema;

return (
<DSTab.Item
{...otherTabItemSchema}
key={childId}
id={childId}
data-testid={TestHelper.generateId(childId, "tab-item")}
title={title}
width={width}
>
<Wrapper>{children}</Wrapper>
</DSTab.Item>
Expand Down
24 changes: 8 additions & 16 deletions src/components/fields/button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import { Button } from "@lifesg/react-design-system/button";
import { Spacing } from "@lifesg/react-design-system/theme";
import * as Icons from "@lifesg/react-icons";
import styled from "styled-components";
import { IGenericFieldProps } from "..";
import { IButtonSchema } from "./types";
import { useFieldEvent } from "../../../utils/hooks";
import { Spacing } from "@lifesg/react-design-system/theme";
import { filterSchemaProps } from "../../../utils/prop-helper";
import { IButtonSchema } from "./types";

export const ButtonField = (props: IGenericFieldProps<IButtonSchema>) => {
// =============================================================================
// CONST, STATE, REF
// =============================================================================
const { id, schema } = props;
const {
schema: {
label,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
uiType,
startIcon,
endIcon,
href,
target,
...otherSchema
},
id,
...otherProps
} = props;
commonSchema: { label },
customSchema: { endIcon, href, startIcon, target, ...buttonProps },
} = filterSchemaProps(schema);
const { dispatchFieldEvent } = useFieldEvent();

// =============================================================================
Expand Down Expand Up @@ -56,7 +48,7 @@ export const ButtonField = (props: IGenericFieldProps<IButtonSchema>) => {
};

return (
<CustomButton type="button" {...otherSchema} {...otherProps} onClick={handleClick}>
<CustomButton type="button" {...buttonProps} onClick={handleClick}>
{renderIcon(startIcon)}
{label}
{renderIcon(endIcon)}
Expand Down
16 changes: 6 additions & 10 deletions src/components/fields/checkbox-group/checkbox-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useFormContext } from "react-hook-form";
import useDeepCompareEffect from "use-deep-compare-effect";
import * as Yup from "yup";
import { IGenericFieldProps } from "..";
import { TestHelper, generateRandomId } from "../../../utils";
import { TestHelper, filterSchemaProps, generateRandomId } from "../../../utils";
import { useValidationConfig } from "../../../utils/hooks";
import { Wrapper } from "../../elements/wrapper";
import { ERROR_MESSAGES, Sanitize, Warning } from "../../shared";
Expand All @@ -16,15 +16,11 @@ export const CheckboxGroup = (props: IGenericFieldProps<TCheckboxGroupSchema>) =
// =============================================================================
// CONST, STATE, REFS
// =============================================================================
const { formattedLabel, error, id, onChange, schema, value, warning } = props;
const {
formattedLabel,
error,
id,
onChange,
schema: { className, customOptions, disabled, label: _label, options, validation, ...otherSchema },
value,
warning,
} = props;
commonSchema: { customOptions, validation },
customSchema: { className, disabled, options, ...checkboxProps },
} = filterSchemaProps(schema);

const { setValue } = useFormContext();
const [stateValue, setStateValue] = useState<string[]>(value || []);
Expand Down Expand Up @@ -115,7 +111,7 @@ export const CheckboxGroup = (props: IGenericFieldProps<TCheckboxGroupSchema>) =
className={className ? `${className}-checkbox-container` : undefined}
>
<StyledCheckbox
{...otherSchema}
{...checkboxProps}
data-testid={TestHelper.generateId(id, "checkbox")}
id={checkboxId}
className={className}
Expand Down
Loading