Skip to content

Commit

Permalink
feat(AsideHeader): add onAllPagesClick callback (#329)
Browse files Browse the repository at this point in the history
* feat(AsideHeader): add onAllPagesClick callback

* fix(AsideHeader): update useMemo dependencies
  • Loading branch information
jenshenJ authored and benax-se committed Nov 12, 2024
1 parent 7f6171f commit ac1f040
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/AsideHeader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const Aside: FC = () => {
| onClosePanel | Callback will be called when closing panel. You can add panels via `PanelItems` prop | `() => void;` | |
| onMenuItemsChanged | Callback will be called when updating list of the menuItems in `AllPagesPanel` | `(items: Array<MenuItem>) => void` | |
| onMenuMoreClick | Callback will be called when some items don't fit and "more" button is clicked | `() => void;` | |
| onAllPagesClick | Callback will be called when "All pages" button is clicked | `() => void;` | |
| openModalSubscriber | Function notifies `AsideHeader` about Modals visibility changes | `( (open: boolean) => void) => void` | |
| panelItems | Items for `Drawer` component. Used for show additional information over main content | [`Array<DrawerItem>`](./../Drawer/README.md#draweritem-props) | `[]` |
| renderContent | Function rendering the main content at the right of the `AsideHeader` | `(data: {size: number}) => React.ReactNode` | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export const AsideHeaderShowcase: React.FC<AsideHeaderShowcaseProps> = ({
setCompact(v);
}}
onMenuMoreClick={() => console.log('onMenuMoreClick')}
onAllPagesClick={() => console.log('onAllPagesClick')}
/>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/AsideHeader/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface AsideHeaderGeneralProps extends QAProps {
onClosePanel?: () => void;
onChangeCompact?: (compact: boolean) => void;
onMenuMoreClick?: () => void;
onAllPagesClick?: () => void;
openModalSubscriber?: (subscriber: OpenModalSubscriber) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const EMPTY_MENU_ITEMS: MenuItem[] = [];
export const useAsideHeaderInnerContextValue = (
props: AsideHeaderProps & {size: number},
): AsideHeaderInnerContextType => {
const {size, onClosePanel, menuItems, panelItems, onMenuItemsChanged} = props;
const {size, onClosePanel, menuItems, panelItems, onMenuItemsChanged, onAllPagesClick} = props;
const [innerVisiblePanel, setInnerVisiblePanel] = useState<InnerPanels | undefined>();
const ALL_PAGES_MENU_ITEM = React.useMemo(() => {
return getAllPagesMenuItem();
Expand Down Expand Up @@ -55,10 +55,11 @@ export const useAsideHeaderInnerContextValue = (
{
...ALL_PAGES_MENU_ITEM,
current: innerVisiblePanel === InnerPanels.AllPages,
onItemClick: onAllPagesClick,
},
]
: menuItems || EMPTY_MENU_ITEMS,
[allPagesIsAvailable, menuItems, innerVisiblePanel, ALL_PAGES_MENU_ITEM],
[allPagesIsAvailable, menuItems, innerVisiblePanel, ALL_PAGES_MENU_ITEM, onAllPagesClick],
);

const innerPanelItems = useMemo(() => {
Expand Down

0 comments on commit ac1f040

Please sign in to comment.