Skip to content

Commit 7637024

Browse files
committed
chore: Bump package version to 1.0.217 and enhance Accordion component
- Update package version in package.json to 1.0.217 - Rename NonInteractive story to NonInteractiveItems for clarity - Add WithNoItems story to handle empty sections in Accordion - Refactor Accordion component to conditionally render draggable items based on section content - Improve styling for section and item interaction
1 parent 4911a82 commit 7637024

File tree

3 files changed

+91
-42
lines changed

3 files changed

+91
-42
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.0.216",
3+
"version": "1.0.217",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {

src/Components/Accordion/Accordion.stories.tsx

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const Interactive = () => {
121121
);
122122
};
123123

124-
export const NonInteractive = () => {
124+
export const NonInteractiveItems = () => {
125125
const [sections, setSections] = useState<ISection[]>([]);
126126
const [expandedSections, setExpandedSections] = useState<number[]>([1]);
127127

@@ -180,8 +180,6 @@ export const WithoutDragAndDrop = () => {
180180
className='yl:w-[500px]'
181181
selectedId={2}
182182
sections={sections}
183-
hasDraggableSectionItems={true}
184-
hasDraggableSections={true}
185183
onSorted={(_, sections) => {
186184
setSections(sections);
187185
}}
@@ -322,6 +320,51 @@ export const WithAddLabels = () => {
322320
);
323321
};
324322

323+
export const WithNoItems = () => {
324+
const [sections, setSections] = useState<ISection[]>([
325+
{
326+
id: 1,
327+
title: "velum constans brevis canis corrumpo magni attollo",
328+
description: "",
329+
order: 0,
330+
items: []
331+
}
332+
]);
333+
const [expandedSections, setExpandedSections] = useState<number[]>([]);
334+
335+
if (!sections.length) {
336+
return <div>Loading...</div>;
337+
}
338+
339+
return (
340+
<div>
341+
<Accordion
342+
className='yl:w-[500px]'
343+
sections={sections}
344+
expanded={expandedSections}
345+
onSorted={(_, sections) => {
346+
setSections(sections);
347+
}}
348+
onAddSection={() => {
349+
action("onAddSection")();
350+
}}
351+
addSectionLabel='Add Course Section'
352+
addSectionItemLabel='Add Course Lecture'
353+
onAddSectionItem={section => {
354+
action("onAddSectionItem")(section);
355+
}}
356+
setExpanded={(expanded: number[]) => {
357+
setExpandedSections(expanded);
358+
action("setExpanded")(expanded);
359+
}}
360+
onSelected={item => {
361+
action("onSelected")(item);
362+
}}
363+
/>
364+
</div>
365+
);
366+
};
367+
325368
export const DefaultExpanded = () => {
326369
const [sections, setSections] = useState<ISection[]>([]);
327370
const [expandedSections, setExpandedSections] = useState<number[]>([]);

src/Components/Accordion/index.tsx

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const Accordion: FC<IAccordionProps> = ({
9494
.map((section, idx) => (
9595
<div
9696
key={section.id}
97-
draggable={hasDraggableSections}
97+
draggable={hasDraggableSections && section.items.length > 0}
9898
onDrag={e => handleDrag(e, section)}
9999
onDragOver={() =>
100100
hasDraggableSections && setDraggedOverId(section.id)
@@ -178,46 +178,52 @@ const Accordion: FC<IAccordionProps> = ({
178178

179179
{expanded.includes(section.id) && (
180180
<>
181-
<DraggableList
182-
items={section.items}
183-
onClick={(item: IDraggableListItem) => {
184-
onSectionItemClick?.(item);
185-
onSelected?.(item);
186-
setSelectedItemId(item.id);
187-
setSelectedSectionId(null);
188-
}}
189-
onDragged={(items: IDraggableListItem[]) => {
190-
onSorted?.(
191-
AccordionOrderType.LECTURES,
192-
[
193-
...sections.map(s =>
194-
s.id === section.id ? { ...s, items } : s
195-
)
196-
],
197-
{ sectionId: section.id, items }
198-
);
199-
}}
200-
isDraggable={hasDraggableSectionItems}
201-
className='yl:gap-4 yl:flex yl:flex-col yl:py-4'
202-
draggedOverClassName='yl:border-t-2 yl:border-border'
203-
liClassName={(item: IDraggableListItem) =>
204-
classNames(
205-
"yl:cursor-default yl:break-words yl:leading-normal yl:px-4",
206-
{
207-
"yl:hover:cursor-pointer yl:hover:text-primary":
208-
onSectionItemClick,
209-
"yl:text-primary":
210-
onSectionItemClick && selectedItemId === item.id,
211-
"yl:pl-5": section.items.length === 1
212-
}
213-
)
214-
}
215-
/>
181+
{section.items.length > 0 && (
182+
<DraggableList
183+
items={section.items}
184+
onClick={(item: IDraggableListItem) => {
185+
onSectionItemClick?.(item);
186+
onSelected?.(item);
187+
setSelectedItemId(item.id);
188+
setSelectedSectionId(
189+
sections.find(s => s.items.includes(item))?.id ?? null
190+
);
191+
}}
192+
onDragged={(items: IDraggableListItem[]) => {
193+
onSorted?.(
194+
AccordionOrderType.LECTURES,
195+
[
196+
...sections.map(s =>
197+
s.id === section.id ? { ...s, items } : s
198+
)
199+
],
200+
{ sectionId: section.id, items }
201+
);
202+
}}
203+
isDraggable={
204+
hasDraggableSectionItems && section.items.length > 0
205+
}
206+
className='yl:gap-4 yl:flex yl:flex-col yl:py-4'
207+
draggedOverClassName='yl:border-t-2 yl:border-border'
208+
liClassName={(item: IDraggableListItem) =>
209+
classNames(
210+
"yl:cursor-default yl:break-words yl:leading-normal yl:px-4",
211+
{
212+
"yl:hover:cursor-pointer yl:hover:text-primary":
213+
onSectionItemClick,
214+
"yl:text-primary":
215+
onSectionItemClick && selectedItemId === item.id,
216+
"yl:pl-5": section.items.length === 1
217+
}
218+
)
219+
}
220+
/>
221+
)}
216222
{onAddSectionItem && (
217223
<div
218224
onClick={() => onAddSectionItem(section)}
219225
className={classNames(
220-
"yl:group yl:border-border yl:hover:bg-text/2 yl:cursor-pointer"
226+
"yl:group yl:border-border yl:hover:bg-text/1 yl:cursor-pointer yl:bg-text/3"
221227
)}
222228
role='presentation'
223229
>
@@ -250,7 +256,7 @@ const Accordion: FC<IAccordionProps> = ({
250256
<div
251257
onClick={onAddSection}
252258
className={classNames(
253-
"yl:group yl:border-2 yl:border-t-0 yl:border-border yl:hover:bg-text/2 yl:rounded-bl-md yl:rounded-br-md yl:cursor-pointer"
259+
"yl:group yl:border-2 yl:border-t-0 yl:border-border yl:hover:bg-text/2 yl:rounded-bl-md yl:rounded-br-md yl:cursor-pointer yl:bg-text/3"
254260
)}
255261
role='presentation'
256262
>

0 commit comments

Comments
 (0)