refactor: remove listWidth prop from List component and associated components (#135)
This commit is contained in:
@@ -83,7 +83,6 @@ const meta = {
|
|||||||
tags: ['autodocs'],
|
tags: ['autodocs'],
|
||||||
argTypes: {
|
argTypes: {
|
||||||
draggableElements: { control: 'object' },
|
draggableElements: { control: 'object' },
|
||||||
listWidth: { control: 'number' },
|
|
||||||
gap: { control: 'number' },
|
gap: { control: 'number' },
|
||||||
},
|
},
|
||||||
} satisfies Meta<typeof List>;
|
} satisfies Meta<typeof List>;
|
||||||
@@ -94,7 +93,11 @@ type Story = StoryObj<typeof meta>;
|
|||||||
export const Default: Story = {
|
export const Default: Story = {
|
||||||
args: {
|
args: {
|
||||||
draggableElements: ExampleCourseBlocks,
|
draggableElements: ExampleCourseBlocks,
|
||||||
listWidth: 300,
|
|
||||||
gap: 12,
|
gap: 12,
|
||||||
},
|
},
|
||||||
|
render: args => (
|
||||||
|
<div className='w-sm'>
|
||||||
|
<List {...args} />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ export default function PopupMain(): JSX.Element {
|
|||||||
draggableElements={activeSchedule?.courses.map((course, i) => (
|
draggableElements={activeSchedule?.courses.map((course, i) => (
|
||||||
<PopupCourseBlock key={course.uniqueId} course={course} colors={tailwindColorways[i]} />
|
<PopupCourseBlock key={course.uniqueId} course={course} colors={tailwindColorways[i]} />
|
||||||
))}
|
))}
|
||||||
listWidth={350}
|
|
||||||
gap={12}
|
gap={12}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function CalendarSchedules({ style, dummySchedules, dummyActiveIndex }: P
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col space-y-2.5'>
|
<div className='flex flex-col space-y-2.5'>
|
||||||
<List gap={10} draggableElements={scheduleComponents} listWidth={240} />
|
<List gap={10} draggableElements={scheduleComponents} />
|
||||||
<input
|
<input
|
||||||
type='text'
|
type='text'
|
||||||
placeholder='Enter new schedule'
|
placeholder='Enter new schedule'
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export default function Dropdown(props: Props) {
|
|||||||
afterLeave={toggleSwitch}
|
afterLeave={toggleSwitch}
|
||||||
>
|
>
|
||||||
<Disclosure.Panel>
|
<Disclosure.Panel>
|
||||||
<List draggableElements={scheduleComponents} listWidth={240} gap={10} />
|
<List draggableElements={scheduleComponents} gap={10} />
|
||||||
</Disclosure.Panel>
|
</Disclosure.Panel>
|
||||||
</Transition>
|
</Transition>
|
||||||
</Disclosure>
|
</Disclosure>
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import React, { useCallback, useEffect, useState } from 'react';
|
|||||||
export interface ListProps {
|
export interface ListProps {
|
||||||
draggableElements: any[]; // TODO: Will later define draggableElements based on what types
|
draggableElements: any[]; // TODO: Will later define draggableElements based on what types
|
||||||
// of components are draggable.
|
// of components are draggable.
|
||||||
listWidth: number;
|
|
||||||
gap: number; // Impacts the spacing between items in the list
|
gap: number; // Impacts the spacing between items in the list
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +57,7 @@ function Item({ provided, item, style, isDragging /* , gap */ }) {
|
|||||||
* @example
|
* @example
|
||||||
* <List draggableElements={elements} />
|
* <List draggableElements={elements} />
|
||||||
*/
|
*/
|
||||||
export default function List({ draggableElements, listWidth, gap = 12 }: ListProps): JSX.Element {
|
export default function List({ draggableElements, gap = 12 }: ListProps): JSX.Element {
|
||||||
const [items, setItems] = useState(() => initial(0, draggableElements));
|
const [items, setItems] = useState(() => initial(0, draggableElements));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -87,7 +86,7 @@ export default function List({ draggableElements, listWidth, gap = 12 }: ListPro
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ overflow: 'hidden', width: listWidth }}>
|
<div style={{ overflow: 'hidden' }}>
|
||||||
<DragDropContext onDragEnd={onDragEnd}>
|
<DragDropContext onDragEnd={onDragEnd}>
|
||||||
<Droppable
|
<Droppable
|
||||||
droppableId='droppable'
|
droppableId='droppable'
|
||||||
@@ -114,12 +113,8 @@ export default function List({ draggableElements, listWidth, gap = 12 }: ListPro
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{provided => (
|
{(provided, snapshot) => (
|
||||||
<div
|
<div {...provided.droppableProps} ref={provided.innerRef} style={{ marginBottom: `-${gap}px` }}>
|
||||||
{...provided.droppableProps}
|
|
||||||
ref={provided.innerRef}
|
|
||||||
style={{ width: `${listWidth}px`, marginBottom: `-${gap}px` }}
|
|
||||||
>
|
|
||||||
{items.map((item, index) => (
|
{items.map((item, index) => (
|
||||||
<Draggable key={item.id} draggableId={item.id} index={index}>
|
<Draggable key={item.id} draggableId={item.id} index={index}>
|
||||||
{draggableProvided => (
|
{draggableProvided => (
|
||||||
|
|||||||
Reference in New Issue
Block a user