-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(omi-templates): tag components & modify default font family
- Loading branch information
Showing
4 changed files
with
70 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Component, tag } from 'omi' | ||
|
||
@tag('o-tag') | ||
export class Tag extends Component { | ||
static defaultProps = { | ||
closable: false, | ||
default: null, | ||
disabled: false, | ||
icon: undefined, | ||
maxWidth: null, | ||
shape: 'square', | ||
size: 'medium', // small, medium, large | ||
theme: 'default', | ||
variant: 'dark', | ||
} | ||
|
||
onClose = (e: MouseEvent) => { | ||
e.stopPropagation() | ||
this.fire('close') | ||
} | ||
|
||
render() { | ||
// @ts-ignore | ||
const { closable, disabled, icon, maxWidth, shape, size, theme, variant } = this.props | ||
|
||
const baseClasses = | ||
'inline-flex items-center justify-center border border-transparent text-base font-medium rounded-sm focus:outline-none transition duration-150 ease-in-out whitespace-nowrap' | ||
const sizeClasses = | ||
size === 'small' ? 'px-1 text-xs h-5' : size === 'medium' ? 'px-3 text-xs h-6' : 'px-4 text-sm h-8' | ||
const shapeClasses = shape === 'square' ? '' : shape === 'round' ? 'rounded' : 'rounded-full' | ||
const themeClasses = | ||
theme === 'default' | ||
? 'bg-zinc-200' | ||
: theme === 'primary' | ||
? 'bg-blue-600' | ||
: theme === 'warning' | ||
? 'bg-yellow-400' | ||
: theme === 'danger' | ||
? 'bg-red-600' | ||
: 'bg-green-500' | ||
const variantClasses = | ||
variant === 'dark' | ||
? 'text-zinc-700' | ||
: variant === 'light' | ||
? 'text-zinc-700' | ||
: variant === 'outline' | ||
? `border ${themeClasses}` | ||
: `border ${themeClasses} bg-white` | ||
const disabledClasses = disabled ? 'cursor-not-allowed' : 'cursor-pointer' | ||
|
||
const cls = `${baseClasses} ${sizeClasses} ${shapeClasses} ${themeClasses} ${variantClasses} ${disabledClasses}` | ||
|
||
return ( | ||
<div className={cls} style={{ maxWidth }}> | ||
{icon && <span className="mr-2">{typeof icon === 'function' ? icon() : icon}</span>} | ||
<slot></slot> | ||
{closable && <i class="t-icon t-icon-close"></i>} | ||
</div> | ||
) | ||
} | ||
} |
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