Skip to content

Commit 9a3cff3

Browse files
author
ange.picard
committed
fix: extract splash component
1 parent b72ab1a commit 9a3cff3

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"types"
1010
],
1111
"scripts": {
12-
"start": "storybook",
12+
"start": "npm run storybook",
1313
"build": "rollup -c && tsc --p tsconfig.lib.json",
1414
"test": "react-scripts test",
1515
"eject": "react-scripts eject",

src/components/ResultList.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
import { Divider, Typography } from "@material-ui/core";
1+
import { Divider } from "@material-ui/core";
22
import React, { FC } from "react";
33
import styled from "styled-components";
44
import NoResultIcon from '../assets/no_result.svg';
55
import DataLoadingIcon from '../assets/data_loading.svg';
66

7-
const SplashHintWrapper = styled.div`
8-
text-align: center;
9-
margin: 32px 16px;
10-
`;
11-
12-
const SplashHint: FC<{ Img: React.ReactNode, headline: string, subline: string }> = ({ Img, headline, subline }) =>
13-
<SplashHintWrapper>
14-
{Img}
15-
<Typography color='textPrimary' variant='body2'>{headline}</Typography>
16-
<Typography color='textSecondary' variant='caption'>{subline}</Typography>
17-
</SplashHintWrapper>
18-
197
const ActualResultListWrapper = styled.ul`
208
list-style: none;
219
padding: 0;
@@ -37,15 +25,17 @@ export interface ResultListProps {
3725
children?: undefined;
3826
loading: boolean;
3927
Results: React.ReactNodeArray;
28+
LoadingSplash: React.ReactNode;
29+
NoResultSplash: React.ReactNode;
4030
}
4131

42-
export const ResultList: FC<ResultListProps> = ({ loading, Results }) => {
32+
export const ResultList: FC<ResultListProps> = ({ loading, LoadingSplash, NoResultSplash, Results }) => {
4333
if (loading) {
44-
return <SplashHint Img={DataLoadingIcon} headline={'Veuillez patienter...'} subline={"Les données chargent."} />;
34+
return <>{LoadingSplash}</>;
4535
}
4636
return (Results && Results.length > 0)
4737
? <ActualResultList Results={Results} />
48-
: <SplashHint Img={NoResultIcon} headline={'Aucun résultat...'} subline={"Peut être avec d'autre mot-clefs ?"} />
38+
: <>{NoResultSplash}</>;
4939
};
5040

5141
export default ResultList;

src/components/SplashHint.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Typography } from "@material-ui/core";
2+
import React, { FC } from "react";
3+
import styled from "styled-components";
4+
5+
const SplashHintWrapper = styled.div`
6+
text-align: center;
7+
margin: 32px 16px;
8+
`;
9+
10+
export interface SplashHintProps {
11+
Img: React.ReactNode;
12+
headline: string;
13+
subline: string;
14+
}
15+
16+
export const SplashHint: FC<SplashHintProps>
17+
= ({ Img, headline, subline }) => (
18+
<SplashHintWrapper>
19+
{Img}
20+
<Typography color='textPrimary' variant='body2'>{headline}</Typography>
21+
<Typography color='textSecondary' variant='caption'>{subline}</Typography>
22+
</SplashHintWrapper>
23+
);
24+
25+
export default SplashHint;

src/components/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export * from './MapButton';
33
export * from './ResultList';
44
export * from './SearchBar';
55
export * from './Sidebar';
6-
export * from './DvcThemeProvider';
6+
export * from './DvcThemeProvider';
7+
export * from './SplashHint';

src/stories/ResultList.stories.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React, { useRef, useState } from 'react';
22
import { ComponentStory, ComponentMeta } from '@storybook/react';
3+
import NoResultIcon from '../assets/no_result.svg';
4+
import DataLoadingIcon from '../assets/data_loading.svg';
35

46
import ResultList from '../components/ResultList';
7+
import { SplashHint } from '../components/SplashHint';
58

69
export default {
710
title: 'Components/ResultList',
@@ -13,14 +16,17 @@ const Template: ComponentStory<typeof ResultList> = (args) => <ResultList {...ar
1316
export const Loading = Template.bind({});
1417
Loading.args = {
1518
loading: true,
19+
LoadingSplash: <SplashHint Img={<img src={DataLoadingIcon} />} headline="Les données arrivent..." subline="Soyez patient :)" />,
20+
NoResultSplash: <div>No result found</div>,
1621
}
1722

1823
export const NoResult = Template.bind({});
1924
NoResult.args = {
20-
Results: []
25+
Results: [],
26+
NoResultSplash: <SplashHint Img={<img src={NoResultIcon} />} headline="Aucun résultat..." subline="Peut être avec d'autre mot clef ?" />,
2127
}
2228

2329
export const Results = Template.bind({});
2430
Results.args = {
25-
Results: ['Banana', 'Lemon', 'Grape'].map(f => <div>{f}</div>)
31+
Results: ['Banana', 'Lemon', 'Grape'].map(f => <button>{f}</button>)
2632
}

0 commit comments

Comments
 (0)