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

Few fixes #137

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 18 additions & 20 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,33 @@ const Chrono: React.FunctionComponent<Partial<TimelineProps>> = (
const initItems = (items?: TimelineItemModel[]) => {
return items && items.length
? items.map((item, index) => {
return Object.assign({}, item, {
id: Math.random().toString(16).slice(2),
visible: true,
active: index === 0,
});
})
: Array.from({
length: React.Children.toArray(children).filter(
(item) => (item as any).props.className !== 'chrono-icons',
).length,
}).map<Partial<TimelineItemModel>>((item, index) => ({
return Object.assign({}, item, {
id: Math.random().toString(16).slice(2),
visible: true,
active: index === 0,
}));
});
})
: Array.from({
length: React.Children.toArray(children).filter(
(item) => (item as any).props.className !== 'chrono-icons',
).length,
}).map<Partial<TimelineItemModel>>((item, index) => ({
id: Math.random().toString(16).slice(2),
visible: true,
active: index === 0,
}));
};

const updateItems = (items: TimelineItemModel[]) => {
if (items) {
const newStartingPosition = items.length - timeLineItems.length;

const newItems = items
.slice(newStartingPosition + 1)
.map((item, index) => ({
...item,
id: Math.random().toString(16).slice(2),
visible: true,
active: index === 0,
}));
const newItems = items.slice(newStartingPosition).map((item, index) => ({
...item,
id: Math.random().toString(16).slice(2),
visible: true,
active: index === 0,
}));

const updatedLineItems = timeLineItems.map((item) => ({
...item,
Expand Down
7 changes: 4 additions & 3 deletions src/components/timeline-elements/memoized/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {

interface Title {
title?: string;
url?: string;
theme?: Theme;
color?: string;
dir?: string;
Expand All @@ -21,16 +22,16 @@ interface Content {
}

const MemoTitle = React.memo(
({ title, theme, color, dir, active }: Title) =>
({ title, url, theme, color, dir, active }: Title) =>
title && theme ? (
<TimelineCardTitle
className={active ? 'active card-title' : 'card-title'}
theme={theme}
style={{ color }}
dir={dir}
>
{title}
</TimelineCardTitle>
<a href={url} target="_blank">{title}</a>
</TimelineCardTitle >
) : null,
() => true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const TimelineCardContent: React.FunctionComponent<TimelineContentModel> = React
onElapsed,
theme,
title,
url,
onClick,
customContent,
hasFocus,
Expand Down Expand Up @@ -230,11 +231,12 @@ const TimelineCardContent: React.FunctionComponent<TimelineContentModel> = React
>
<TimelineCardHeader>
{/* main title */}
{!media && <MemoTitle title={title} theme={theme} />}
{!media &&
<MemoTitle title={title} url={url} theme={theme} />
}
{/* main timeline text */}
{!media && <MemoSubTitle content={content} theme={theme} />}
</TimelineCardHeader>

{/* render media video or image */}
{media && (
<CardMedia
Expand All @@ -250,7 +252,6 @@ const TimelineCardContent: React.FunctionComponent<TimelineContentModel> = React
title={title}
/>
)}

{/* detailed text */}
<TimelineContentDetailsWrapper
aria-expanded={showMore}
Expand All @@ -270,8 +271,8 @@ const TimelineCardContent: React.FunctionComponent<TimelineContentModel> = React
>
{Array.isArray(detailedText)
? detailedText.map((text, index) => (
<TimelineSubContent key={index}>{text}</TimelineSubContent>
))
<TimelineSubContent key={index}>{text}</TimelineSubContent>
))
: detailedText}
</TimelineContentDetails>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ const CardMedia: React.FunctionComponent<CardMediaModel> = ({
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
src={`${media.source.url}${
active ? '?autoplay=1&enablejsapi=1' : '?enablejsapi=1'
}`}
src={`${media.source.url}${active ? '?autoplay=1&enablejsapi=1' : '?enablejsapi=1'
}`}
/>
),
[active],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ test('Test Timeline Item render - Horizontal Class', () => {
const element = screen.getByTestId('timeline-item');
const titleElement = screen.getByTestId('timeline-title');

console.log(element.className);

expect(element).toHaveClass('horizontal');
expect(titleElement).toHaveClass('horizontal top');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const TimelineCard: React.FunctionComponent<TimelineCardModel> = ({
cardDetailedText,
cardSubtitle,
cardTitle,
url,
id,
media,
onClick,
Expand Down Expand Up @@ -66,7 +67,7 @@ const TimelineCard: React.FunctionComponent<TimelineCardModel> = ({
}
}, [active, autoScroll, mode]);

const handleOnShowMore = useCallback(() => {}, []);
const handleOnShowMore = useCallback(() => { }, []);

const modeLower = useMemo(() => mode?.toLowerCase(), [mode]);

Expand Down Expand Up @@ -100,6 +101,7 @@ const TimelineCard: React.FunctionComponent<TimelineCardModel> = ({
content={cardSubtitle}
active={active}
title={cardTitle}
url={url}
detailedText={cardDetailedText}
onShowMore={handleOnShowMore}
theme={theme}
Expand Down
3 changes: 3 additions & 0 deletions src/components/timeline-vertical/timeline-vertical-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const VerticalItem: React.FunctionComponent<VerticalItemModel> = (
cardDetailedText,
cardSubtitle,
cardTitle,
url,
className,
contentDetailsChildren,
iconChild,
Expand Down Expand Up @@ -84,6 +85,7 @@ const VerticalItem: React.FunctionComponent<VerticalItemModel> = (
const contentClass = cls('card-content-wrapper', visible ? 'visible' : '', {
[className]: true,
});

return (
<TimelineCardContentWrapper
className={contentClass}
Expand All @@ -106,6 +108,7 @@ const VerticalItem: React.FunctionComponent<VerticalItemModel> = (
slideShowActive={slideShowRunning}
theme={theme}
title={cardTitle}
url={url}
/>
</TimelineCardContentWrapper>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/timeline-vertical/timeline-vertical.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const TimelineVertical: React.FunctionComponent<TimelineVerticalModel> = ({
);

// todo remove this
const handleOnShowMore = useCallback(() => {}, []);
const handleOnShowMore = useCallback(() => { }, []);

return (
<TimelineVerticalWrapper data-testid="tree-main" role="list">
Expand Down
6 changes: 3 additions & 3 deletions src/components/timeline/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ const Timeline: React.FunctionComponent<TimelineModel> = (
.querySelectorAll('img,video')
.forEach(
(ele) =>
((ele as HTMLElement).style.visibility =
state === 'hide' ? 'hidden' : 'visible'),
((ele as HTMLElement).style.visibility =
state === 'hide' ? 'hidden' : 'visible'),
);
};

Expand Down Expand Up @@ -231,7 +231,7 @@ const Timeline: React.FunctionComponent<TimelineModel> = (
if (mode === 'VERTICAL' || mode === 'VERTICAL_ALTERNATING') {
scrolled = target.scrollTop + target.clientHeight;

if (target.scrollHeight === scrolled) {
if ((target.scrollHeight - scrolled) < 1) {
onScrollEnd && onScrollEnd();
}
} else {
Expand Down
127 changes: 64 additions & 63 deletions src/demo/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const NewDemo: React.FunctionComponent = () => {

useEffect(() => {
const newItems = data.map(
({ title, cardTitle, cardSubtitle, cardDetailedText, id }) => ({
({ title, url, cardTitle, cardSubtitle, cardDetailedText, id }) => ({
title,
url,
cardTitle,
cardSubtitle,
cardDetailedText,
Expand All @@ -33,75 +34,75 @@ const NewDemo: React.FunctionComponent = () => {
setItems(newItems);
}, []);

const [state, setState] = useState(0);
const [state, setState] = useState(0);

return (
<Wrapper>
<h3>Timeline of World War 2</h3>
<BrowserRouter>
<header>
<ComponentLinks>
<li>
<Link to="/vertical-basic">Vertical Basic</Link>
</li>
<li>
<Link to="/vertical-alternating">Vertical Alternating</Link>
</li>
<li>
<Link to="/vertical-alternating-mixed">Vertical Alternating Mixed Data</Link>
</li>
<li>
<Link to="/horizontal">Horizontal Basic</Link>
</li>
<li>
<Link to="/vertical-custom">Vertical Custom contents</Link>
</li>
<li>
<Link to="/vertical-custom-icon">Vertical Custom Icons</Link>
</li>
<li>
<Link to="/dynamic-load">Dynamic data load</Link>
</li>
</ComponentLinks>
</header>
<section>
<Switch>
<Route path="/vertical-basic">
{/* Vertical with no Media */}
{items.length > 0 && (
<VerticalBasic type={"big-screen"} items={items} />
)}
</Route>
<Route path="/vertical-alternating-mixed">
{items.length > 0 && <VerticalTreeMixed type={"big-screen"} />}
</Route>
<Route path="/vertical-alternating">
<button onClick={() => {
setState(1 - state)
}}>change</button>
{<VerticalTree type={'big-screen'} items={state > 0 ? items : mixed} >{state}</VerticalTree>}
</Route>
<Route path="/horizontal">
{items.length > 0 && (
<HorizontalBasic items={items} type="big-screen" />
)}
</Route>
<Route path="/vertical-custom">
{items.length > 0 && <VerticalCustomContent type="big-screen" />}
</Route>
<Route path="/vertical-custom-icon">
{items.length > 0 && <VerticalCustomContent2 type="big-screen" />}
</Route>
<Route path="/dynamic-load">
{items.length > 0 && <DynamicLoad />}
</Route>
<Route path="/">
{items.length > 0 && (
<header>
<ComponentLinks>
<li>
<Link to="/vertical-basic">Vertical Basic</Link>
</li>
<li>
<Link to="/vertical-alternating">Vertical Alternating</Link>
</li>
<li>
<Link to="/vertical-alternating-mixed">Vertical Alternating Mixed Data</Link>
</li>
<li>
<Link to="/horizontal">Horizontal Basic</Link>
</li>
<li>
<Link to="/vertical-custom">Vertical Custom contents</Link>
</li>
<li>
<Link to="/vertical-custom-icon">Vertical Custom Icons</Link>
</li>
<li>
<Link to="/dynamic-load">Dynamic data load</Link>
</li>
</ComponentLinks>
</header>
<section>
<Switch>
<Route path="/vertical-basic">
{/* Vertical with no Media */}
{items.length > 0 && (
<VerticalBasic type={"big-screen"} items={items} />
)}
</Route>
</Switch>
</section>
</Route>
<Route path="/vertical-alternating-mixed">
{items.length > 0 && <VerticalTreeMixed type={"big-screen"} />}
</Route>
<Route path="/vertical-alternating">
<button onClick={() => {
setState(1 - state)
}}>change</button>
{<VerticalTree type={'big-screen'} items={state > 0 ? items : mixed} >{state}</VerticalTree>}
</Route>
<Route path="/horizontal">
{items.length > 0 && (
<HorizontalBasic items={items} type="big-screen" />
)}
</Route>
<Route path="/vertical-custom">
{items.length > 0 && <VerticalCustomContent type="big-screen" />}
</Route>
<Route path="/vertical-custom-icon">
{items.length > 0 && <VerticalCustomContent2 type="big-screen" />}
</Route>
<Route path="/dynamic-load">
{items.length > 0 && <DynamicLoad />}
</Route>
<Route path="/">
{items.length > 0 && (
<VerticalBasic type={"big-screen"} items={items} />
)}
</Route>
</Switch>
</section>
</BrowserRouter>
</Wrapper>
);
Expand Down
Loading