Skip to content

Commit

Permalink
feat(eden): text组件
Browse files Browse the repository at this point in the history
  • Loading branch information
mark9804 committed Jan 2, 2024
1 parent 57b7e9a commit 1edf53f
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 61 deletions.
52 changes: 26 additions & 26 deletions lib/eden-design/docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export default defineConfig({
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
lastUpdated: {
text: '最后更新于',
text: "最后更新于",
formatOptions: {
dateStyle: 'medium',
timeStyle: 'short',
dateStyle: "medium",
timeStyle: "short",
forceLocale: true,
}
},
},
search: {
provider: "local",
Expand Down Expand Up @@ -82,29 +82,29 @@ export default defineConfig({
text: "字体 / Typography",
link: "/guideline/design/#字体-typography",
},
// {
// text: "图标 / Iconography",
// link: "/guideline/design/#图标-iconography",
// },
// {
// text: "阴影 / Shadow",
// link: "/guideline/design/#阴影-shadow",
// },
// {
// text: "动画 / Animation",
// link: "/guideline/design/#动画-animation",
// },
// {
// text: "布局 / Layout",
// link: "/guideline/design/#布局-layout",
// },
// {
// text: "交互 / Interaction",
// link: "/guideline/design/#交互-interaction",
// },
]
{
text: "图标 / Iconography",
link: "/guideline/design/#图标-iconography",
},
{
text: "阴影 / Shadow",
link: "/guideline/design/#阴影-shadow",
},
{
text: "布局 / Layout",
link: "/guideline/design/#布局-layout",
},
{
text: "交互 / Interaction",
link: "/guideline/design/#交互-interaction",
},
],
},
{
text: "设计语言",
link: "/guideline/design/design-language",
items: [],
},
{ text: "设计语言", link: "/guideline/design/design-language", items: [] },
],

socialLinks: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ const props = withDefaults(defineProps<IconProps>(), {

<template>
<svg
width="24"
height="24"
class="eden-ui__icon"
:width="props.size"
:height="props.size"
viewBox="0 0 48 48"
:fill="filled ? color : 'none'"
:transform="`rotate(${props.rotate})`"
>
<path
d="M36 18L24 30L12 18"
:stroke="color"
:stroke="filled ? 'none' : color"
stroke-width="4"
stroke-linecap="round"
stroke-linejoin="round"
Expand Down
24 changes: 4 additions & 20 deletions lib/eden-design/packages/eden-ui/components/Menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,9 @@ import MenuItem from "./src/EdenMenuItem.vue";
import MenuItemGroup from "./src/EdenMenuItemGroup.vue";
import SubMenu from "./src/EdenSubMenu.vue";
import type { App } from "vue";
Menu.name = "menu";
MenuItem.name = "menu-item";
MenuItemGroup.name = "menu-item-group";
SubMenu.name = "sub-menu";

Menu.install = (app: App) => {
app.component(Menu.name, Menu);
};

MenuItem.install = (app: App) => {
app.component(MenuItem.name, MenuItem);
};

MenuItemGroup.install = (app: App) => {
app.component(MenuItemGroup.name, MenuItemGroup);
};

SubMenu.install = (app: App) => {
app.component(SubMenu.name, SubMenu);
};
Menu.__name = "menu";
MenuItem.__name = "menu-item";
MenuItemGroup.__name = "menu-item-group";
SubMenu.__name = "sub-menu";

export { Menu, MenuItem, MenuItemGroup, SubMenu };
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ const menuItemTriage = [
.eden-ui__menu {
font-family: var(--eden-main-font);
width: 256px;
padding-left: 20px;
padding-top: 32px;
padding: 32px 20px 0 20px;
border-right: 1px solid #00000010;
display: flex;
flex-direction: column;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts"></script>

<template>
<div>MenuItem</div>
<div class="eden-ui__menu__menuitem">MenuItem</div>
</template>

<style scoped lang="scss"></style>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "radix-vue";
import { IMenuData } from "../types/MenuProps";
const props = withDefaults(defineProps<IMenuData>(), {
title: "SubMenuDefaultTitle",
groupName: "SubMenuDefaultGroupName",
route: {
path: "/",
},
Expand All @@ -17,11 +17,24 @@ const isOpen = ref(false);
</script>

<template>
<CollapsibleRoot>
<div>{{ props.title }}</div>
<CollapsibleTrigger @click="isOpen = !isOpen">
<chevron />
</CollapsibleTrigger>
<CollapsibleRoot
:open="isOpen"
:class="[
'eden-ui__menu__submenu',
{
active: isOpen,
},
]"
>
<div class="eden-ui__menu__submenu__title">
<div v-if="props.groupName">{{ props.groupName }}</div>
<CollapsibleTrigger @click="isOpen = !isOpen">
<chevron :rotate="isOpen ? 90 : 0" />
</CollapsibleTrigger>
</div>
<CollapsibleContent>
<slot></slot>
</CollapsibleContent>
</CollapsibleRoot>
</template>

Expand Down
5 changes: 5 additions & 0 deletions lib/eden-design/packages/eden-ui/components/Text/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Text from "./src/EdenText.vue";

Text.__name = "text";

export { Text };
81 changes: 81 additions & 0 deletions lib/eden-design/packages/eden-ui/components/Text/src/EdenText.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<script setup lang="ts">
import { TextProps } from "../types/Text";
import { textSizeMap } from "../style/textProps";
import { computed } from "vue";
const props = withDefaults(defineProps<TextProps>(), {
size: "body-2",
level: 5,
role: "text",
});
const textStyle = computed(() => {
const sizeProps = textSizeMap
.filter(item => item.textSize === props.size)
.pop();
return {
fontSize: sizeProps?.fontSize,
lineHeight: sizeProps?.lineHeight,
color:
props.color && "string" === typeof props.color
? props.color
: `var(--color-text-${props.level}, #242424)`,
};
});
function getGradientDegree(degree: number | string | undefined) {
switch (typeof degree) {
case "number":
return `${degree}deg`;
case "string":
return degree;
default:
return "0deg";
}
}
const gradientStyle = computed(() => {
if ("object" === typeof props.color) {
return {
backgroundImage: `linear-gradient(${getGradientDegree(props.color.deg)},${
props.color.from
}, ${props.color.to})`,
WebkitBackgroundClip: "text",
WebkitTextFillColor: "transparent",
};
}
});
</script>

<template>
<p
:class="[
'eden-ui__text',
{
'is-title': props.role === 'title' || props.size.startsWith('display'),
'no-select': props.noSelect,
disabled: props.disabled,
},
]"
:style="[textStyle, gradientStyle]"
>
<slot></slot>
</p>
</template>

<style scoped lang="scss">
.eden-ui__text {
&.is-title {
font-family: var(--eden-title-font);
font-weight: var(--eden-title-font-weight);
}
&.no-select {
user-select: none;
}
&.disabled {
cursor: not-allowed;
color: var(--color-text-2);
}
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export const textSizeMap = [
{
textSize: "body-3",
fontSize: "14px",
lineHeight: "22px",
},
{
textSize: "body-2",
fontSize: "16px",
lineHeight: "24px",
},
{
textSize: "body-1",
fontSize: "18px",
lineHeight: "26px",
},
{
textSize: "title-3",
fontSize: "20px",
lineHeight: "28px",
},
{
textSize: "title-2",
fontSize: "24px",
lineHeight: "32px",
},
{
textSize: "title-1",
fontSize: "28px",
lineHeight: "36px",
},
{
textSize: "display-3",
fontSize: "32px",
lineHeight: "40px",
},
{
textSize: "display-2",
fontSize: "48px",
lineHeight: "56px",
},
{
textSize: "display-1",
fontSize: "64px",
lineHeight: "76px",
},
];
23 changes: 23 additions & 0 deletions lib/eden-design/packages/eden-ui/components/Text/types/Text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export type TextProps = {
size?:
| "body-3"
| "body-2"
| "body-1"
| "title-3"
| "title-2"
| "title-1"
| "display-3"
| "display-2"
| "display-1";
role?: "text" | "title";
level?: 5 | 4 | 3 | 2 | 1 | "5" | "4" | "3" | "2" | "1";
noSelect?: boolean;
disabled?: boolean;
color?:
| string
| {
from: string;
to: string;
deg?: number | string;
};
};
5 changes: 3 additions & 2 deletions lib/eden-design/packages/eden-ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import type { App } from "vue";
import "./styles.scss";
import { Menu, MenuItem, MenuItemGroup, SubMenu } from "./components/Menu";
import { Button } from "./components/Button";
import { Text } from "./components/Text";

const components = [Button, Menu, MenuItem, MenuItemGroup, SubMenu];
const components = [Button, Menu, MenuItem, MenuItemGroup, SubMenu, Text];
const componentPrefix = "e";

const install = (app: App) => {
components.forEach(item => {
app.component(`${componentPrefix}-${item.name}`, item);
app.component(`${componentPrefix}-${item.__name}`, item);
});
};

Expand Down
Loading

0 comments on commit 1edf53f

Please sign in to comment.