-
Notifications
You must be signed in to change notification settings - Fork 41
feat(tinytag): replace svg to render #517
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
99b5fd3
feat(tinytag): replace svg to render
745940a
test(tinytag): update tinyTag snapshots
5ed4de0
feat(tinytag): remove default font-family && currentColor in svg
0e672a2
fix(tinytag): compute padding error && change height 15px
ad66bf1
feat(tinytag): add useSvgWidth
da30fbc
feat(tinytag): update useSvgWidth hooks && change ref binding dom
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
| .data-tag { | ||
| color: #D1D1D1; | ||
| &:hover { | ||
| color: #D56161; | ||
| } | ||
| } | ||
|
|
||
| .ued-tag { | ||
| color: #D56161; | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,21 +1,51 @@ | ||
| import React from 'react'; | ||
| import React, { useEffect, useRef, useState } from 'react'; | ||
| import classNames from 'classnames'; | ||
|
|
||
| import './style.scss'; | ||
|
|
||
| interface ITinyTag extends React.HTMLAttributes<HTMLSpanElement> { | ||
| value?: string; | ||
| color?: string; | ||
| value: string; | ||
| } | ||
|
|
||
| export default function TinyTag({ color, value, className, ...restProps }: ITinyTag) { | ||
| export default function TinyTag({ value, className, ...restProps }: ITinyTag) { | ||
| const domRef = useRef<HTMLDivElement>(null); | ||
shiqiWang0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const [width, setWidth] = useState(0); | ||
|
|
||
| const getTextWidth = () => { | ||
| const text = domRef?.current?.getElementsByTagName('text')?.[0]; | ||
| const paddingWidth = 8; | ||
| if (!text) return; | ||
| const textWidth = Math.round(text.getBoundingClientRect()?.width); | ||
| const widthSvg = textWidth + paddingWidth; | ||
| setWidth(widthSvg); | ||
| }; | ||
| useEffect(() => { | ||
| getTextWidth(); | ||
| }, []); | ||
| return ( | ||
| <span | ||
| className={classNames('dtc-tinyTag', className)} | ||
| style={{ borderColor: color, color }} | ||
| {...restProps} | ||
| > | ||
| {value} | ||
| <span ref={domRef} className={classNames('dtc-tinyTag', className)} {...restProps}> | ||
| <svg | ||
| width={width} | ||
| height="15" | ||
| viewBox={`0 0 ${width} 15`} | ||
| fill="none" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <rect | ||
| x="0.5" | ||
| y="0.5" | ||
| width={width - 1} | ||
|
||
| height="14" | ||
| rx="1.5" | ||
| stroke="currentColor" | ||
| strokeLinejoin="bevel" | ||
| /> | ||
| <text fill="currentColor" xmlSpace="preserve" fontSize="10" letterSpacing="0px"> | ||
| <tspan x="4" y="11.1"> | ||
| {value} | ||
| </tspan> | ||
| </text> | ||
| </svg> | ||
| </span> | ||
| ); | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,16 +1,5 @@ | ||
| $primaryColor: #1D78FF; | ||
| $factor: 0.83; | ||
|
|
||
| .dtc-tinyTag { | ||
| border-radius: 2px; | ||
| border: 1px solid $primaryColor; | ||
| font-weight: 400; | ||
| color: $primaryColor; | ||
| line-height: calc(15px / $factor); | ||
| padding: 0 calc(4px / $factor); | ||
| font-size: 12px; | ||
| display: inline-block; | ||
| transform: scale($factor); | ||
| user-select: none; | ||
| white-space: nowrap; | ||
| display: inline-block; | ||
| transform: translateY(3px); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.