-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): handle TabbedLayout fullWidth, elements focus-visible
- Loading branch information
1 parent
9f6a9ee
commit ca01987
Showing
9 changed files
with
137 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/client/src/elements/layouts/TabbedLayout/TabbedLayout.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Children, isValidElement, ReactNode } from 'react'; | ||
|
||
import { Role } from '../../../enums/role.enum'; | ||
import { User } from '../../../providers/api/CurrentUserProvider/CurrentUserProvider.types'; | ||
import { TabsVariant } from './TabbedLayout.types'; | ||
|
||
export const getIndicatorPosition = ( | ||
value: number, | ||
totalChildren: number, | ||
containerWidth: number, | ||
tabWidth: number, | ||
tabIndicatorSize: number, | ||
variant: TabsVariant, | ||
widthOnFullSize: number, | ||
): number => { | ||
console.log('L:32 | tabIndicatorSize: ', tabIndicatorSize); // TODO: handle indicator width diff | ||
|
||
const totalChildrenWidth = totalChildren * tabWidth; | ||
const totalEmptyWidth = containerWidth - totalChildrenWidth; | ||
const singleEmptyWidth = totalEmptyWidth / (totalChildren + 1); | ||
const trimmedSingleEmptyWidth = singleEmptyWidth <= 0 ? 0 : singleEmptyWidth; | ||
|
||
if (variant === 'fullWidth') { | ||
return value * widthOnFullSize; | ||
} | ||
|
||
if (value === 0) { | ||
return trimmedSingleEmptyWidth; | ||
} | ||
|
||
const emptyWidthForValue = (value + 1) * trimmedSingleEmptyWidth; | ||
const tabsWidthForValue = value * tabWidth; | ||
|
||
return emptyWidthForValue + tabsWidthForValue; | ||
}; | ||
|
||
export const hasAccess = (onlyAdmin: boolean, user?: User) => | ||
!(onlyAdmin && !user?.roles.includes(Role.Admin)); | ||
|
||
export const countAvailableChildren = (children: ReactNode, user?: User) => | ||
Children.count( | ||
Children.map(children, (child) => { | ||
if (isValidElement(child)) { | ||
const { onlyAdmin } = child.props; | ||
if (hasAccess(onlyAdmin, user)) { | ||
return child; | ||
} | ||
} | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters