Skip to content

Commit 7a34c99

Browse files
authored
refactor(layout): less to cssinjs (#6249)
1 parent dc480bd commit 7a34c99

File tree

9 files changed

+263
-175
lines changed

9 files changed

+263
-175
lines changed

components/layout/layout.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ExtractPropTypes, HTMLAttributes } from 'vue';
22
import { computed, createVNode, defineComponent, provide, ref } from 'vue';
33
import useConfigInject from '../config-provider/hooks/useConfigInject';
44
import { SiderHookProviderKey } from './injectionKey';
5+
import useStyle from './style';
56

67
export const basicProps = () => ({
78
prefixCls: String,
@@ -18,7 +19,7 @@ type GeneratorArgument = {
1819
};
1920

2021
function generator({ suffixCls, tagName, name }: GeneratorArgument) {
21-
return (BasicComponent: typeof Basic) => {
22+
return (BasicComponent: typeof BasicLayout) => {
2223
const Adapter = defineComponent({
2324
compatConfig: { MODE: 3 },
2425
name,
@@ -49,9 +50,11 @@ const Basic = defineComponent({
4950

5051
const BasicLayout = defineComponent({
5152
compatConfig: { MODE: 3 },
53+
inheritAttrs: false,
5254
props: basicProps(),
53-
setup(props, { slots }) {
54-
const { direction } = useConfigInject('', props);
55+
setup(props, { slots, attrs }) {
56+
const { prefixCls, direction } = useConfigInject('', props);
57+
const [wrapSSR, hashId] = useStyle(prefixCls);
5558
const siders = ref<string[]>([]);
5659
const siderHookProvider = {
5760
addSider: (id: string) => {
@@ -66,6 +69,7 @@ const BasicLayout = defineComponent({
6669
const divCls = computed(() => {
6770
const { prefixCls, hasSider } = props;
6871
return {
72+
[hashId.value]: true,
6973
[`${prefixCls}`]: true,
7074
[`${prefixCls}-has-sider`]:
7175
typeof hasSider === 'boolean' ? hasSider : siders.value.length > 0,
@@ -74,7 +78,7 @@ const BasicLayout = defineComponent({
7478
});
7579
return () => {
7680
const { tagName } = props;
77-
return createVNode(tagName, { class: divCls.value }, slots);
81+
return wrapSSR(createVNode(tagName, { ...attrs, class: [divCls.value, attrs.class] }, slots));
7882
};
7983
},
8084
});

components/layout/style/index.less

-145
This file was deleted.

0 commit comments

Comments
 (0)