Skip to content

Commit 0b0e812

Browse files
committed
Update CategoryPanel to use dynamic data and refine imports
Refactored `CategoryPanel` to accept `data` as a prop instead of relying on hardcoded `mockData`. Updated storybook configuration to provide mock data and improve the preview handling. Also switched from an alpha version to a stable release of `@acrool/js-utils`.
1 parent 53ad91b commit 0b0e812

File tree

5 files changed

+48
-55
lines changed

5 files changed

+48
-55
lines changed

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"styled-components": "6.1.17"
1515
},
1616
"dependencies": {
17-
"@acrool/js-utils": "^3.2.23-alpha.0",
17+
"@acrool/js-utils": "^3.2.23",
1818
"@acrool/react-carousel": "link:..",
1919
"@acrool/react-grid": "^6.0.7",
2020
"@acrool/react-iconsvg": "^4.2.1",

example/src/components/examples/CategoryPanel/CategoryPanel.stories.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Phone, {NavWrapper} from '@/components/atoms/Phone';
66
import Icon, {EIconCode} from '@/library/acrool-react-icon';
77

88
import CategoryPanel from './_components/CategoryPanel';
9+
import {mockData} from './_components/mockData';
910

1011

1112
const meta = {
@@ -20,6 +21,9 @@ const meta = {
2021
},
2122
},
2223
},
24+
args: {
25+
data: mockData,
26+
},
2327
render: function Render(args) {
2428
return <Phone>
2529

@@ -50,9 +54,6 @@ const meta = {
5054

5155
</Phone>;
5256
},
53-
// argTypes: {},
54-
args: {
55-
},
5657
} satisfies Meta<typeof CategoryPanel>;
5758

5859
export default meta;

example/src/components/examples/CategoryPanel/_components/CategoryPanel.tsx

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {Img} from '@acrool/react-img';
55
import {useEffect, useState} from 'react';
66
import styled, {css} from 'styled-components';
77

8-
import {mockData} from './mockData';
98
import {IBallCategoryCarouselData, IBallCategoryCarouselProps} from './types';
109

1110

@@ -17,74 +16,69 @@ import {IBallCategoryCarouselData, IBallCategoryCarouselProps} from './types';
1716
* Component / Molecules @ Live Event 輪播
1817
*/
1918
const CategoryPanel = ({
19+
data,
2020
}: IBallCategoryCarouselProps) => {
2121
const [activeId, onSetActiveId] = useState<string|null>(null);
2222
const [controller, setController] = useState<Controller|null>(null);
23-
const [previewData, setPreviewData] = useState<IBallCategoryCarouselData[]|undefined>(undefined);
24-
const [startIndex, setStartIndex] = useState<number>(0);
23+
const [previewData, setPreviewData] = useState<IBallCategoryCarouselData[]|undefined>(data?.slice(0, 6));
2524

2625

2726
useEffect(() => {
28-
setTimeout(() => {
29-
setPreviewData(mockData.slice(0, 6));
30-
},1);
31-
}, []);
27+
setPreviewData(data.slice(0, 6));
28+
}, [data]);
3229

3330

3431

3532

3633
const handleOnClick = (id: string) => {
37-
const currIndex = mockData.findIndex(row => row.id === id);
34+
const currIndex = data.findIndex(row => row.id === id);
3835
if(currIndex === -1) return;
3936

4037

4138
const pageIndex = Math.floor(currIndex / 6);
4239
const startIndex = pageIndex * 6;
4340
const endIndex = startIndex + 6;
44-
const filterData = mockData.slice(startIndex, endIndex);
41+
const filterData = data.slice(startIndex, endIndex);
4542

4643
setPreviewData(filterData);
47-
setStartIndex(startIndex);
48-
// setTimeout(() => {
49-
// }, 1);
50-
5144
onSetActiveId(id);
5245
controller?.slideToPage(1);
5346

5447
};
5548

5649

5750
const getCarouselData = (): TAcroolSlideItemDataList => {
58-
const dataPaginate = mockData ? arraySplit(mockData,18) : undefined;
59-
60-
61-
const dataList2 = [
62-
<AcroolSlideCard key={`preview_${startIndex}`}>
63-
<Row className="flex-nowrap g-2">
64-
{
65-
previewData
66-
?.map(row => {
67-
const isActive = row.id === activeId;
68-
69-
return <Col col={12/6}
70-
key={`preview_col_${row.id}`}
71-
>
72-
<Card $active={row.id === activeId} onClick={() => {
73-
onSetActiveId(row.id);
74-
}}>
75-
<div className="position-relative">
76-
<Img src={isActive ? row.activePath: row.path} width={28} height={28} className="mt-1"/>
77-
<Count>{row.count}</Count>
78-
</div>
79-
<Name className="text-overflow">{row.name}</Name>
80-
<ActiveLine/>
81-
</Card>
82-
</Col>;
83-
})
84-
}
85-
</Row>
86-
87-
</AcroolSlideCard>,
51+
const dataPaginate = data ? arraySplit(data,18) : undefined;
52+
53+
54+
return [
55+
...(previewData ? [
56+
<AcroolSlideCard key={'preview_'}>
57+
<Row className="flex-nowrap g-2">
58+
{
59+
previewData
60+
?.map(row => {
61+
const isActive = row.id === activeId;
62+
63+
return <Col col={12/6}
64+
key={`preview_col_${row.id}`}
65+
>
66+
<Card $active={row.id === activeId} onClick={() => {
67+
onSetActiveId(row.id);
68+
}}>
69+
<div className="position-relative">
70+
<Img src={isActive ? row.activePath: row.path} width={28} height={28} className="mt-1"/>
71+
<Count>{row.count}</Count>
72+
</div>
73+
<Name className="text-overflow">{row.name}</Name>
74+
<ActiveLine/>
75+
</Card>
76+
</Col>;
77+
})
78+
}
79+
</Row>
80+
81+
</AcroolSlideCard>]: []),
8882
...dataPaginate?.map((page, idx) => {
8983
return <AcroolSlideCard key={`real_${idx}`}>
9084
<Row>
@@ -114,9 +108,6 @@ const CategoryPanel = ({
114108

115109
}) ?? []
116110
];
117-
118-
return dataList2;
119-
120111
};
121112

122113

@@ -223,7 +214,7 @@ const Card = styled.div<{
223214

224215
const CustomAcroolCarousel = styled(AcroolCarousel)`
225216
.acrool-react-carousel__container{
226-
//min-height: 64px;
217+
height: 64px;
227218
}
228219
`;
229220

example/src/components/examples/CategoryPanel/_components/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export interface IBallCategoryCarouselData {
88
}
99

1010
export interface IBallCategoryCarouselProps {
11+
data: IBallCategoryCarouselData[]
1112
}
1213

example/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# yarn lockfile v1
33

44

5-
"@acrool/js-utils@^3.2.23-alpha.0":
6-
version "3.2.23-alpha.0"
7-
resolved "https://registry.yarnpkg.com/@acrool/js-utils/-/js-utils-3.2.23-alpha.0.tgz#8cf9417b788f607cd124b23e4d0cc83fb679b6ab"
8-
integrity sha512-cssAwTZauip01C2q+MHBuNRVhpGDspI155+VMlNho6dOUiHGxPrPEqvX6KHFpyJpsOVdp2rwh9B4zVj679RwpA==
5+
"@acrool/js-utils@^3.2.23":
6+
version "3.2.23"
7+
resolved "https://registry.yarnpkg.com/@acrool/js-utils/-/js-utils-3.2.23.tgz#43bbac5d92cf3318167ba246b57d0a52bfa382ac"
8+
integrity sha512-Yy/yXg5+Q8VZC6CFLtJUrUhZltVzcIXAooAWhLJ9ONvWT+AEcy4DDBkv3YZUblOj5vNhE4s4RWt/ukWOB9aEIQ==
99
dependencies:
1010
big.js "^7.0.1"
1111
dayjs "^1.x"

0 commit comments

Comments
 (0)