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 all 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,12 +43,12 @@ export const MobileNavigation: FC<MobileNavigationProps> = ({ menu, panel, showP
<MobileAddonsDrawer>{panel}</MobileAddonsDrawer>
<Button onClick={() => setMobileMenuOpen(!isMobileMenuOpen)} title="Open navigation menu">
<Icons icon="menu" />
{fullStoryName}
<Text>{fullStoryName}</Text>
</Button>
{showPanel && (
<DrawerIconButton onClick={() => setMobilePanelOpen(true)} title="Open addon panel">
<IconButton onClick={() => setMobilePanelOpen(true)} title="Open addon panel">
<Icons icon="bottombartoggle" />
</DrawerIconButton>
</IconButton>
)}
</Container>
);
Expand All @@ -71,12 +69,6 @@ const Container = styled.div(({ theme }) => ({
color: theme.color.mediumdark,
}));

// We should not have to reset the margin-top here
// TODO: remove this once we have a the new IconButton component
const DrawerIconButton = styled(IconButton)({
marginTop: 0,
});

const Button = styled.button(({ theme }) => ({
all: 'unset',
display: 'flex',
Expand All @@ -86,4 +78,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,
},
}));

const Text = styled.p({
display: '-webkit-box',
WebkitLineClamp: 1,
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
});