-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
feat: add ribbon #3681
Merged
Merged
feat: add ribbon #3681
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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,52 @@ | ||
import { LiteralUnion } from '../_util/type'; | ||
import { PresetColorType } from '../_util/colors'; | ||
import { isPresetColor } from './utils'; | ||
import { defaultConfigProvider } from '../config-provider'; | ||
import { HTMLAttributes, FunctionalComponent, VNodeTypes, inject, CSSProperties } from 'vue'; | ||
|
||
type RibbonPlacement = 'start' | 'end'; | ||
|
||
export interface RibbonProps extends HTMLAttributes { | ||
prefixCls?: string; | ||
text?: VNodeTypes; | ||
color?: LiteralUnion<PresetColorType, string>; | ||
placement?: RibbonPlacement; | ||
} | ||
|
||
const Ribbon: FunctionalComponent<RibbonProps> = (props, { attrs, slots }) => { | ||
const { prefixCls: customizePrefixCls, color, text, placement = 'end' } = props; | ||
const { class: className, style } = attrs; | ||
const children = slots.default?.(); | ||
const { getPrefixCls, direction } = inject('configProvider', defaultConfigProvider); | ||
|
||
const prefixCls = getPrefixCls('ribbon', customizePrefixCls); | ||
const colorInPreset = isPresetColor(color); | ||
const ribbonCls = [ | ||
prefixCls, | ||
`${prefixCls}-placement-${placement}`, | ||
{ | ||
[`${prefixCls}-rtl`]: direction === 'rtl', | ||
[`${prefixCls}-color-${color}`]: colorInPreset, | ||
}, | ||
className, | ||
]; | ||
const colorStyle: CSSProperties = {}; | ||
const cornerColorStyle: CSSProperties = {}; | ||
if (color && !colorInPreset) { | ||
colorStyle.background = color; | ||
cornerColorStyle.color = color; | ||
} | ||
return ( | ||
<div class={`${prefixCls}-wrapper`}> | ||
{children} | ||
<div class={ribbonCls} style={{ ...colorStyle, ...(style as CSSProperties) }}> | ||
<span class={`${prefixCls}-text`}>{text}</span> | ||
<div class={`${prefixCls}-corner`} style={cornerColorStyle} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
Ribbon.displayName = 'ABadgeRibbon'; | ||
|
||
export default Ribbon; |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import Badge from './Badge'; | ||
import { withInstall } from '../_util/type'; | ||
|
||
export default withInstall(Badge); | ||
export default Badge; |
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 |
---|---|---|
|
@@ -188,3 +188,5 @@ | |
opacity: 0; | ||
} | ||
} | ||
|
||
@import './ribbon'; |
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,81 @@ | ||
@import '../../style/themes/index'; | ||
@import '../../style/mixins/index'; | ||
|
||
@ribbon-prefix-cls: ~'@{ant-prefix}-ribbon'; | ||
@ribbon-wrapper-prefix-cls: ~'@{ant-prefix}-ribbon-wrapper'; | ||
|
||
.@{ribbon-wrapper-prefix-cls} { | ||
position: relative; | ||
} | ||
|
||
.@{ribbon-prefix-cls} { | ||
.reset-component(); | ||
|
||
position: absolute; | ||
top: 8px; | ||
height: 22px; | ||
padding: 0 8px; | ||
color: @badge-text-color; | ||
line-height: 22px; | ||
white-space: nowrap; | ||
background-color: @primary-color; | ||
border-radius: @border-radius-sm; | ||
|
||
&-text { | ||
color: @white; | ||
} | ||
|
||
&-corner { | ||
position: absolute; | ||
top: 100%; | ||
width: 8px; | ||
height: 8px; | ||
color: currentColor; | ||
border: 4px solid; | ||
transform: scaleY(0.75); | ||
transform-origin: top; | ||
// If not support IE 11, use filter: brightness(75%) instead | ||
&::after { | ||
position: absolute; | ||
top: -4px; | ||
left: -4px; | ||
width: inherit; | ||
height: inherit; | ||
color: rgba(0, 0, 0, 0.25); | ||
border: inherit; | ||
content: ''; | ||
} | ||
} | ||
|
||
// colors | ||
// mixin to iterate over colors and create CSS class for each one | ||
.make-color-classes(@i: length(@preset-colors)) when (@i > 0) { | ||
.make-color-classes(@i - 1); | ||
@color: extract(@preset-colors, @i); | ||
@darkColor: '@{color}-6'; | ||
&-color-@{color} { | ||
color: @@darkColor; | ||
background: @@darkColor; | ||
} | ||
} | ||
.make-color-classes(); | ||
|
||
// placement | ||
&.@{ribbon-prefix-cls}-placement-end { | ||
right: -8px; | ||
border-bottom-right-radius: 0; | ||
.@{ribbon-prefix-cls}-corner { | ||
right: 0; | ||
border-color: currentColor transparent transparent currentColor; | ||
} | ||
} | ||
|
||
&.@{ribbon-prefix-cls}-placement-start { | ||
left: -8px; | ||
border-bottom-left-radius: 0; | ||
.@{ribbon-prefix-cls}-corner { | ||
left: 0; | ||
border-color: currentColor currentColor transparent transparent; | ||
} | ||
} | ||
} |
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,5 @@ | ||
import { PresetColorTypes } from '../_util/colors'; | ||
|
||
export function isPresetColor(color?: string): boolean { | ||
return (PresetColorTypes as any[]).indexOf(color) !== -1; | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1、属性没声明,从props里面拿不到啊
2、text 支持slot
3、没有声明 inheritAttrs: false class和style 会被挂载到根节点上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done