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

[Restitution] Ajout classModifier & change type #852

Merged
merged 2 commits into from
Feb 19, 2021
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 packages/restitution/src/HeaderRestitution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const HeaderRestitution = ({
<header className={className}>
<div className="af-restitution__header-left">
<div className="af-restitution__title">
{title && <span className="af-restitution__title-title">{title}</span>}
{title && <span className="af-restitution__title-main">{title}</span>}
<span className="af-restitution__title-subtitle">{subtitle}</span>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/restitution/src/Restitution.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export const Default = () => (
]}
/>
</SectionRestitutionColumn>
<SectionRestitutionColumn>
<SectionRestitutionColumn classModifier="test">
<Restitution label="TA" value="99,99 %" />
<Restitution label="EURO" value="EURO" />
<Restitution label="TT" value="" />
<Restitution label="TT" value={undefined} />
<Restitution
label="Garanties complémentaires"
classModifier="marge"
Expand Down
59 changes: 24 additions & 35 deletions packages/restitution/src/Restitution.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ComponentPropsWithoutRef } from 'react';
import {
withClassDefault,
withClassModifier,
Expand All @@ -9,19 +9,8 @@ import {

const DEFAULT_CLASSNAME = 'af-restitution__listdef';

type RestitutionValuesProps = {
values: string[];
};

type RestitutionProps = WithClassModifierOptions &
Partial<RestitutionValuesProps> & {
label: string;
value?: string;
className?: string;
};

const RestitutionValues = ({ values }: RestitutionValuesProps) => {
const li = values.map((v: string) => (
const RestitutionValues = ({ values }: Pick<RestitutionProps, 'values'>) => {
const li = values.map((v) => (
<li key={v} className="af-restitution__listul-item">
{v}
</li>
Expand All @@ -30,34 +19,34 @@ const RestitutionValues = ({ values }: RestitutionValuesProps) => {
return <ul className="af-restitution__listul">{li}</ul>;
};

const Restitution = ({ label, value, values, className }: RestitutionProps) => {
let restitutionValue = values ? <RestitutionValues values={values} /> : value;

if (!restitutionValue) {
restitutionValue = '-';
}

return (
<dl className={className}>
<dt className="af-restitution__listdef-item">
<span className="af-restitution__text">{label}</span>
</dt>
<dd className="af-restitution__listdef-value">{restitutionValue}</dd>
</dl>
);
};

const defaultProps: Partial<RestitutionProps> = {
className: DEFAULT_CLASSNAME,
type RestitutionProps = ComponentPropsWithoutRef<'dl'> & {
label: string;
value?: string;
values?: string[];
};
const Restitution = ({
label,
value = '-',
values,
className,
}: RestitutionProps) => (
<dl className={className}>
<dt className="af-restitution__listdef-item">
<span className="af-restitution__text">{label}</span>
</dt>
<dd className="af-restitution__listdef-value">
{values ? <RestitutionValues values={values} /> : value}
</dd>
</dl>
);

type RestitutionEnhancedProps = WithClassModifierOptions & RestitutionProps;
const enhance = compose(
identity<RestitutionProps>(),
identity<RestitutionEnhancedProps>(),
withClassDefault(DEFAULT_CLASSNAME),
withClassModifier()
);

const Enhanced = enhance(Restitution);
Enhanced.displayName = 'Restitution';
Enhanced.defaultProps = defaultProps;
export default Enhanced;
10 changes: 2 additions & 8 deletions packages/restitution/src/SectionRestitutionColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type SectionRestitutionColumnBaseProps = {
children?: React.ReactNode;
};

export const SectionRestitutionColumn = ({
const SectionRestitutionColumn = ({
children,
className,
title,
Expand All @@ -31,18 +31,12 @@ type SectionRestitutionColumnProps = WithClassModifierOptions &
SectionRestitutionColumnBaseProps;

const enhance = compose(
identity<SectionRestitutionColumnBaseProps>(),
identity<SectionRestitutionColumnProps>(),
withClassDefault(DEFAULT_CLASSNAME),
withClassModifier()
);

const defaultProps: Partial<SectionRestitutionColumnProps> = {
children: null,
className: DEFAULT_CLASSNAME,
};

const Enhanced = enhance(SectionRestitutionColumn);
Enhanced.displayName = 'SectionRestitutionColumn';
Enhanced.defaultProps = defaultProps;

export default Enhanced;
10 changes: 2 additions & 8 deletions packages/restitution/src/SectionRestitutionTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@ const Restitution = ({ title, className }: RestitutionBaseProps) => (
<div className={className}>{title}</div>
);

type RestitutionProps = WithClassModifierOptions & RestitutionBaseProps;
const enhance = compose(
identity<RestitutionBaseProps>(),
identity<RestitutionProps>(),
withClassDefault(DEFAULT_CLASSNAME),
withClassModifier()
);

type RestitutionProps = WithClassModifierOptions & RestitutionBaseProps;

const defaultProps: Partial<RestitutionProps> = {
className: DEFAULT_CLASSNAME,
};

const Enhanced = enhance(Restitution);
Enhanced.displayName = 'SectionTitle';
Enhanced.defaultProps = defaultProps;

export default Enhanced;
Loading