Skip to content
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(example): 支持omi组件格式 #48

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions script/plugin-tdoc/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function renderDemo(md, container) {
const [, demoPath, componentName = ''] = match;
const demoPathOnlyLetters = demoPath.replace(/[^a-zA-Z\d]/g, '');
const demoName = path.basename(demoPath).trim();
const demoDefName = `Demo${demoPathOnlyLetters}`;
const demoDefName = `Demo${demoPathOnlyLetters}Component`;
const demoCodeDefName = `Demo${demoPathOnlyLetters}Code`;

const tpl = `
Expand All @@ -34,7 +34,7 @@ export default function renderDemo(md, container) {

</div>
<div className="tdesign-demo-item__body">
<div style={{width: '100%'}}><${demoDefName} /></div>
<div style={{width: '100%'}}>{${demoDefName}}</div>
</div>
</td-doc-demo>
`;
Expand Down
5 changes: 3 additions & 2 deletions script/plugin-tdoc/md-to-wc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ function getGitTimestamp(file) {

export default async function mdToReact(options) {
const mdSegment = await customRender(options);
const { demoDefsStr, demoCodesDefsStr } = options;
const { demoDefsStr, demoCodesDefsStr, components } = options;

const reactSource = `
import { h } from 'omi';
import { h, define } from 'omi';
import { signal, effect } from 'reactive-signal'
import Prismjs from 'prismjs';
import 'prismjs/components/prism-bash.js';
${demoDefsStr}
${demoCodesDefsStr}
${components}

export default function TdDoc() {
const isComponent = ${mdSegment.isComponent};
Expand Down
15 changes: 15 additions & 0 deletions script/plugin-tdoc/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,27 @@ export default {
.map((key) => demoCodesImports[key])
.join('\n');

const components = Object.keys(demoImports)
.map(
(key) => `
let ${key}Component = null;
if('${key}'.endsWith('omi')){
define('t-${key.toLocaleLowerCase()}', ${key});
${key}Component = <t-${key.toLocaleLowerCase()} />;
} else {
${key}Component = <${key} />;
};
`,
)
.join('\n');

const sfc = mdToWc({
md,
file,
source,
demoDefsStr,
demoCodesDefsStr,
components,
});
return sfc;
},
Expand Down
2 changes: 1 addition & 1 deletion src/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spline: base

### 基础使用

{{ base }}
{{ base-omi }}

### 图标按钮

Expand Down
24 changes: 24 additions & 0 deletions src/button/_example/base-omi.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'tdesign-web-components/button';

import { Component } from 'omi';

export default class Button extends Component {
render() {
return (
<div style={{ gap: 16, display: 'inline-flex' }}>
<t-button theme="default" variant="base">
填充按钮
</t-button>
<t-button theme="default" variant="outline">
描边按钮
</t-button>
<t-button theme="default" variant="dashed">
虚框按钮
</t-button>
<t-button theme="default" variant="text">
文字按钮
</t-button>
</div>
);
}
}
Loading