Skip to content

Commit

Permalink
chore: refactor to use utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
haideralsh committed Oct 2, 2023
1 parent 5a16f59 commit b6368c0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/BrandedNavBar/NavBar.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import theme from "../theme";
import { Button } from "../Button";
import { Text } from "../Type";
import { BrandedNavBar as NDSBrandedNavBar } from "./index";
import numberFromDimension from "../utils/numberFromDimension";

const sampleLogo = "http://pigment.github.io/fake-logos/logos/vector/color/auto-speed.svg";

Expand Down Expand Up @@ -389,9 +390,9 @@ export const WithHamburgerMenu = () => {
};
WithHamburgerMenu.parameters = {
viewport: {
defaultViewport: "small", // for some reason this has to match the viewport key, NOT the name!
defaultViewport: "small", // for some reason, this has to match the viewport key, NOT the name!
},
chromatic: { viewports: [parseInt(theme.breakpoints.small)] },
chromatic: { viewports: [numberFromDimension(theme.breakpoints.small)] },
};

const customPrimaryMenu = [
Expand Down Expand Up @@ -428,7 +429,7 @@ CustomRenderingInHamburger.parameters = {
viewport: {
defaultViewport: "small", // for some reason this has to match the viewport key, NOT the name!
},
chromatic: { viewports: [parseInt(theme.breakpoints.small)] },
chromatic: { viewports: [numberFromDimension(theme.breakpoints.small)] },
};

const primaryMenuWithCustomTriggers = [
Expand Down Expand Up @@ -487,5 +488,5 @@ CustomMenuTriggersInHamburger.parameters = {
viewport: {
defaultViewport: "small", // for some reason this has to match the viewport key, NOT the name!
},
chromatic: { viewports: [parseInt(theme.breakpoints.small)] },
chromatic: { viewports: [numberFromDimension(theme.breakpoints.small)] },
};
3 changes: 2 additions & 1 deletion src/BrandedNavBar/SmallNavBar.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Link } from "../Link";
import { Button, SmallNavBarProps, theme } from "../index";
import BrandLogoContainer from "./BrandLogoContainer";
import { SmallNavBar } from "./index";
import numberFromDimension from "../utils/numberFromDimension";

const ResetStorybookView = styled.div({
position: "absolute",
Expand Down Expand Up @@ -78,7 +79,7 @@ const smallViewport = {
viewport: {
defaultViewport: "small", // for some reason this has to match the viewport key, NOT the name!
},
chromatic: { viewports: [parseInt(theme.breakpoints.small)] },
chromatic: { viewports: [numberFromDimension(theme.breakpoints.small)] },
};

export default {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/numberFromDimension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
* Returns the number from a [CSS dimension]{@link https://developer.mozilla.org/en-US/docs/Web/CSS/dimension}.
* @param {string} dimension - A css dimension
*/
export default function (dimension: string | number): number {
export default function numberFromDimension(dimension: string | number): number {
return parseInt(String(dimension), 10);
}

0 comments on commit b6368c0

Please sign in to comment.