Skip to content

Commit

Permalink
feat(omi-templates): tag components & modify default font family
Browse files Browse the repository at this point in the history
  • Loading branch information
dntzhang committed Feb 12, 2024
1 parent 2809f3c commit fdb7085
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/omi-templates/src/components/omiu/table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, tag } from 'omi'
import './tag.tsx'

@tag('o-table')
export class Table extends Component {
Expand Down Expand Up @@ -72,7 +73,9 @@ export class Table extends Component {
</th>
<td class="px-6 py-4 w-24">银色</td>
<td class="px-6 py-4 w-24">Laptop</td>
<td class="px-6 py-4 w-20">是</td>
<td class="px-6 py-4 w-20">
<o-tag>带有</o-tag>
</td>
<td class="px-6 py-4 w-20">是</td>
<td class="px-6 py-4 w-24">¥12999</td>
<td class="px-6 py-4 w-24">3.0kg</td>
Expand Down
61 changes: 61 additions & 0 deletions packages/omi-templates/src/components/omiu/tag.tsx
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>
)
}
}
4 changes: 1 addition & 3 deletions packages/omi-templates/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ export class Sidebar extends Component<Props> {
})}
>
<div>
<div
class={classNames('flex items-center h-[50px] space-x-2 justify-center')}
>
<div class={classNames('flex items-center h-[50px] space-x-2 justify-center')}>
<i class="h-8 w-8">
<img src="https://omi.cdn-go.cn/admin/latest/home/omi.svg"></img>
</i>
Expand Down
4 changes: 4 additions & 0 deletions packages/omi-templates/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export default {
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
fontFamily: {
// https://tailwindcss.com/docs/font-family#customizing-the-default-font
sans: '-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Hiragino Sans GB,Microsoft YaHei UI,Microsoft YaHei,Source Han Sans CN,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'
},
extend: {
typography: {
DEFAULT: {
Expand Down

0 comments on commit fdb7085

Please sign in to comment.