-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More migrating components, filling out the Order Summary and cart ite…
…ms display, update API client
- Loading branch information
Showing
11 changed files
with
4,105 additions
and
3,336 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Canvas, Meta } from "@storybook/blocks" | ||
|
||
import * as TruncateTextStories from "./TruncateText.stories" | ||
|
||
<Meta of={TruncateTextStories} /> | ||
|
||
# TruncateText | ||
|
||
Use `lineClamp` to truncate text after a certain number of lines: | ||
|
||
`lineClamp={1}` | ||
|
||
<Canvas of={TruncateTextStories.One} /> | ||
|
||
`lineClamp={3}` | ||
|
||
<Canvas of={TruncateTextStories.Three} /> | ||
|
||
`lineClamp={"none"}` | ||
|
||
<Canvas of={TruncateTextStories.None} /> |
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,42 @@ | ||
import type { Meta, StoryObj } from "@storybook/react" | ||
import { TruncateText } from "./TruncateText" | ||
|
||
const meta: Meta<typeof TruncateText> = { | ||
title: "smoot-design/TruncateText", | ||
component: TruncateText, | ||
argTypes: { | ||
lineClamp: { | ||
options: ["none", 1, 2, 3, 4, 5], | ||
control: { | ||
type: "select", | ||
}, | ||
}, | ||
}, | ||
args: { | ||
lineClamp: 1, | ||
children: | ||
"This is a long text that should be truncated after a few lines. ".repeat( | ||
30, | ||
), | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof TruncateText> | ||
|
||
export const None: Story = { | ||
args: { | ||
lineClamp: "none", | ||
}, | ||
} | ||
export const One: Story = { | ||
args: { | ||
lineClamp: 1, | ||
}, | ||
} | ||
export const Three: Story = { | ||
args: { | ||
lineClamp: 3, | ||
}, | ||
} |
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,34 @@ | ||
import { css } from "@emotion/react" | ||
import styled from "@emotion/styled" | ||
|
||
type TruncateTextProps = { | ||
/** | ||
* Number of lines to display before truncating text. | ||
*/ | ||
lineClamp?: number | "none" | ||
} | ||
|
||
const truncateText = (lines?: number | "none") => | ||
css({ | ||
display: "-webkit-box", | ||
WebkitBoxOrient: "vertical", | ||
overflow: "hidden", | ||
textOverflow: "ellipsis", | ||
WebkitLineClamp: lines, | ||
[`@supports (-webkit-line-clamp: ${lines})`]: { | ||
whiteSpace: "initial", | ||
display: "-webkit-box", | ||
WebkitLineClamp: `${lines}`, // cast to any to avoid typechecking error in lines, | ||
WebkitBoxOrient: "vertical", | ||
}, | ||
}) | ||
|
||
/** | ||
* Truncate the content after specified number of lines. | ||
*/ | ||
const TruncateText = styled.div<TruncateTextProps>(({ lineClamp: lines }) => | ||
truncateText(lines), | ||
) | ||
|
||
export { TruncateText, truncateText } | ||
export type { TruncateTextProps } |
Oops, something went wrong.