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

docs: Updated the virtualizedList to tsx #2545

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions .hintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"development"
],
"hints": {
"no-inline-styles": "off"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,43 @@ import { generateItems } from "./VirtualizedList.stories.helpers";
import { Flex } from "../../";
import styles from "./VirtualizedList.module.scss";

export default {
title: "Navigation/VirtualizedList",
component: VirtualizedList
};
interface Item {
height: number;
value: string;
size: number;
}

interface VirtualizedListProps {
items: Item[];
itemRenderer: (item: Item, index: number, style: React.CSSProperties) => JSX.Element;
getItemSize: (item: Item) => number;
layout?: "vertical" | "horizontal";
}

const virtualizedListTemplate = args => {
const itemRenderer = useCallback((item, index, style) => {
const backgroundColor = index % 2 === 0 ? "#e1e1e1" : "#f8f8f0";
return (
<div key={index} style={style}>
<div
className={styles.virtualizedListItem}
style={{
backgroundColor,
height: item.height
}}
>
{item.value}
// Defining the component type properly
const VirtualizedListTemplate: React.FC<VirtualizedListProps> = (args: unknown) => {
const itemRenderer = useCallback(
(item: Item, index: number, style: React.CSSProperties): JSX.Element => {
const backgroundColor = index % 2 === 0 ? "#e1e1e1" : "#f8f8f0";
return (
<div key={index} style={style}>
<div
className={styles.virtualizedListItem}
style={{
backgroundColor,
height: item.height
}}
>
{item.value}
</div>
</div>
</div>
);
}, []);
);
},
[]
);

return (
<Flex align={Flex.align.START} gap={Flex.gaps.LARGE} style={{ width: "100%" }} direction={Flex.directions.ROW}>
<Flex align="start" gap="large" style={{ width: "100%" }} direction="row">
<div
style={{
width: 330,
Expand All @@ -43,7 +56,7 @@ const virtualizedListTemplate = args => {
{...args}
items={generateItems(30, 1000, "vertical")}
itemRenderer={itemRenderer}
getItemSize={item => item.size}
getItemSize={(item: Item) => item.size}
/>
</div>
</div>
Expand All @@ -62,7 +75,7 @@ const virtualizedListTemplate = args => {
{...args}
items={generateItems(100, 1000, "horizontal")}
itemRenderer={itemRenderer}
getItemSize={item => item.size}
getItemSize={(item: Item) => item.size}
layout="horizontal"
/>
</div>
Expand All @@ -71,7 +84,8 @@ const virtualizedListTemplate = args => {
);
};

// Fixing the export type
export const Overview = {
render: virtualizedListTemplate.bind({}),
render: VirtualizedListTemplate.bind({}),
name: "Overview"
};
};