Skip to content

Commit

Permalink
new prop disableToolbar for hiding toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhuignoto committed Mar 7, 2024
1 parent 0a86716 commit b443994
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ Below are the available configuration options for the component:
| flipLayout | false | Reverses the layout (Right to Left). |
| focusActiveItemOnLoad | false | Automatically scrolls to and focuses on the `activeItemIndex` when loading. |
| fontSizes | | Allows customization of font sizes. |
| hideControls | false | Hides navigation controls. |
| highlightCardsOnHover | false | Highlights the card on hover |
| items | [] | A collection of Timeline Item Models. |
| itemWidth | 300 | Sets the width of the timeline section in horizontal mode. |
Expand Down Expand Up @@ -201,6 +200,7 @@ Below are the available configuration options for the component:
| toolbarPosition | TOP | Configures the position of the toolbar. Can be `TOP` or `BOTTOM` |
| uniqueId | | Used with `noUniqueId` to set a custom unique id for the wrapper. |
| useReadMore | true | Enables or disables the "read more" button. Available if text content on the card is taller than the card itself. |
| disableToolbar | false | Disables and hides the toolbar |

### Mode

Expand Down
1 change: 1 addition & 0 deletions src/components/GlobalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const GlobalContextProvider: FunctionComponent<ContextProps> = (props) => {
disableClickOnCircle: !!props.disableInteraction,
disableInteraction: false,
disableTimelinePoint: !!props.disableInteraction,
disableToolbar: false,
enableBreakPoint: true,
enableDarkToggle: false,
enableLayoutSwitch: true,
Expand Down
2 changes: 0 additions & 2 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const Chrono: React.FunctionComponent<Partial<TimelineProps>> = (
activeItemIndex = 0,
titleDateFormat = 'MMM DD, YYYY',
mode,
hideControls,
} = props;

const [timeLineItems, setTimeLineItems] = useState<TimelineItemModel[]>([]);
Expand Down Expand Up @@ -210,7 +209,6 @@ const Chrono: React.FunctionComponent<Partial<TimelineProps>> = (
onItemSelected={onItemSelected}
onOutlineSelection={handleOutlineSelection}
mode={mode}
hideControls={hideControls}
onPaused={onPaused}
/>
</GlobalContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ const TimelineCardContent: React.FunctionComponent<TimelineContentModel> =
<Timeline
items={items}
mode={'VERTICAL'}
hideControls
nestedCardHeight={nestedCardHeight}
isChild
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/timeline/__tests__/timeline.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('Timeline', () => {
const commonProps: TimelineModel = {
activeTimelineItem: 0,
contentDetailsChildren: null,
hideControls: false,
iconChildren: null,
isChild: false,
items: [
Expand Down
1 change: 0 additions & 1 deletion src/components/timeline/timeline.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import styled from 'styled-components';
import { ScrollBar } from '../common/styles';

export const Wrapper = styled.div<{
$hideControls?: boolean;
cardPositionHorizontal?: 'TOP' | 'BOTTOM';
}>`
display: flex;
Expand Down
9 changes: 6 additions & 3 deletions src/components/timeline/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const Timeline: React.FunctionComponent<TimelineModel> = (
slideShowEnabled,
slideShowRunning,
mode = 'HORIZONTAL',
hideControls = false,
nestedCardHeight,
isChild = false,
onPaused,
Expand All @@ -68,6 +67,7 @@ const Timeline: React.FunctionComponent<TimelineModel> = (
updateHorizontalAllCards,
toolbarPosition,
updateTextContentDensity,
disableToolbar,
} = useContext(GlobalContext);

const [newOffSet, setNewOffset] = useNewScrollPosition(mode, itemWidth);
Expand Down Expand Up @@ -327,6 +327,10 @@ const Timeline: React.FunctionComponent<TimelineModel> = (
});
}, [mode, isChild]);

const canShowToolbar = useMemo(() => {
return !disableToolbar && !isChild;
}, [isChild, disableToolbar]);

return (
<Wrapper
onKeyDown={handleKeyDown}
Expand All @@ -335,14 +339,13 @@ const Timeline: React.FunctionComponent<TimelineModel> = (
onMouseDown={() => {
setHasFocus(true);
}}
$hideControls={hideControls}
onKeyUp={(evt) => {
if (evt.key === 'Escape') {
onPaused?.();
}
}}
>
{!isChild ? (
{canShowToolbar ? (
<ToolbarWrapper position={toolbarPosition}>
<TimelineToolbar
activeTimelineItem={activeTimelineItem}
Expand Down
1 change: 1 addition & 0 deletions src/demo/vertical-samples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const VerticalTree: FunctionComponent<{
slideShowType="slide_from_sides"
allowDynamicUpdate
cardHeight={200}
disableToolbar
// textOverlay
focusActiveItemOnLoad
enableDarkToggle
Expand Down
6 changes: 2 additions & 4 deletions src/models/TimelineModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export type TimelineModel = Pick<
| 'slideShow'
| 'onScrollEnd'
| 'mode'
| 'hideControls'
| 'timelinePointDimension'
| 'nestedCardHeight'
| 'noUniqueId'
Expand Down Expand Up @@ -136,6 +135,8 @@ export type TimelineProps = {

disableTimelinePoint?: boolean;

disableToolbar?: boolean;

enableBreakPoint?: boolean;

enableDarkToggle?: boolean;
Expand All @@ -158,9 +159,6 @@ export type TimelineProps = {
title?: string;
};

// hides the ui controls
hideControls?: boolean;

highlightCardsOnHover?: boolean;

itemWidth?: number;
Expand Down

0 comments on commit b443994

Please sign in to comment.