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

UI: Mobile truncate story name #24372

Merged
merged 6 commits into from
Oct 10, 2023
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ const useFullStoryName = () => {
const { index } = useStorybookState();
const currentStory = useStorybookApi().getCurrentStoryData();

if (!currentStory) {
return '';
}
if (!currentStory) return '';

let fullStoryName = currentStory.renderLabel?.(currentStory) || currentStory.name;
let node = index[currentStory.id];

while ('parent' in node && node.parent && index[node.parent]) {
while ('parent' in node && node.parent && index[node.parent] && fullStoryName.length < 24) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't make it stop at 24 characters, it will just make sure that it doesn't add more parents when it has exceeded 24 characters.

Take this example:

Long Root Parent Name/Loooooooong Name/Medium Name/Short Name
  ^21 char           ^    ^16 char    ^  ^11 char ^  ^10 char

Will result in:

Loooooooong Name/Medium Name/Short Name
    ^16 char    ^  ^11 char ^   ^10 char
= 39 characters

Which is still better than nothing, but I just wanted to make sure we all understood this.
If we wanted this to always stop at 24 characters, we would afterwards remove any characters before the last 24 with a substr or similar, which would result in:

e/Medium Name/Short Name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @JReinhold. We don't want to stop exactly at 24 characters. This is just an arbitrary number based on the tests I made to get a sense as to when we can put the parent or not. If the parent has a long name for example, we will use the css truncate with "..." to actually truncate the text.

node = index[node.parent];
const parentName = node.renderLabel?.(node) || node.name;
fullStoryName = `${parentName}/${fullStoryName}`;
Expand All @@ -45,7 +43,7 @@ export const MobileNavigation: FC<MobileNavigationProps> = ({ menu, panel, showP
<MobileAddonsDrawer>{panel}</MobileAddonsDrawer>
<Button onClick={() => setMobileMenuOpen(!isMobileMenuOpen)} title="Open navigation menu">
<Icons icon="menu" />
{fullStoryName}
<p>{fullStoryName}</p>
</Button>
{showPanel && (
<DrawerIconButton onClick={() => setMobilePanelOpen(true)} title="Open addon panel">
Expand Down Expand Up @@ -86,4 +84,18 @@ const Button = styled.button(({ theme }) => ({
fontSize: `${theme.typography.size.s2 - 1}px`,
padding: '0 7px',
fontWeight: theme.typography.weight.bold,
WebkitLineClamp: 1,

'> svg': {
width: 14,
height: 14,
flexShrink: 0,
},

'> p': {
display: '-webkit-box',
WebkitLineClamp: 1,
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
},
JReinhold marked this conversation as resolved.
Show resolved Hide resolved
}));