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

Docs: 添加商店表单支持 #2460

Merged
merged 28 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
59a5e7f
:memo: add store form
StarHeartHunt Nov 20, 2023
38ec00a
:memo: fix typo
StarHeartHunt Nov 20, 2023
b3ffc24
:memo: not allow to skip required value
StarHeartHunt Nov 20, 2023
318b69f
:memo: fix label text color
StarHeartHunt Nov 20, 2023
f82f0b7
:memo: css tweaks
StarHeartHunt Nov 20, 2023
662d00a
:memo: fix plugin issue title
StarHeartHunt Nov 20, 2023
8f0fc31
:memo: extract styles into css
StarHeartHunt Nov 20, 2023
3976093
:memo: fix format
StarHeartHunt Nov 20, 2023
ea8c182
:memo: fix style
StarHeartHunt Nov 20, 2023
db072ff
:memo: fix hidden
StarHeartHunt Nov 20, 2023
b045001
:memo: lint tweak
StarHeartHunt Nov 20, 2023
d621d8d
:memo: style tweaks
StarHeartHunt Nov 20, 2023
37e9c04
:memo: greater width on desktop devices
StarHeartHunt Nov 20, 2023
32995da
:memo: fix input error border style
StarHeartHunt Nov 21, 2023
7e3bed5
:art: shorten var name
StarHeartHunt Nov 21, 2023
2deaef6
:fire: remove label type
StarHeartHunt Nov 21, 2023
1769ecd
:sparkles: support auto complete
StarHeartHunt Nov 21, 2023
35982a3
:bug: fix color picker dark mode
StarHeartHunt Nov 21, 2023
bb267ab
:sparkles: init plugin and adapter detail modal
StarHeartHunt Nov 21, 2023
87a4ad1
:sparkles: add copy
StarHeartHunt Nov 21, 2023
b59b5bc
Update website/src/components/Store/Content/Plugin.tsx
StarHeartHunt Nov 22, 2023
d4e03e1
Update website/src/components/Store/Content/Driver.tsx
StarHeartHunt Nov 22, 2023
550b83a
:bug: resolve css name conflict
StarHeartHunt Nov 22, 2023
27b0daa
:lipstick: use theme close button
StarHeartHunt Nov 22, 2023
cd70e83
:bug: fix tag gap
StarHeartHunt Nov 22, 2023
19636eb
:sparkles: add requires python data
StarHeartHunt Nov 22, 2023
f12051b
:bug: fix step button hidden on bound
StarHeartHunt Nov 22, 2023
14bb558
:art: use fixed width of fa
StarHeartHunt Nov 22, 2023
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
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "^2.4.1",
"@tsconfig/docusaurus": "^1.0.5",
"@types/react-color": "^3.0.10",
"asciinema-player": "^3.5.0",
"typescript": "^4.7.4"
},
Expand Down
51 changes: 51 additions & 0 deletions website/src/components/Form/Adapter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from "react";

import { Form } from ".";

export default function AdapterForm(): JSX.Element {
const formItems = [
{
name: "基本信息",
items: [
{
type: "text",
name: "name",
labelText: "适配器名称",
},
{ type: "text", name: "description", labelText: "适配器描述" },
{
type: "text",
name: "homepage",
labelText: "适配器项目仓库/主页链接",
},
],
},
{
name: "包信息",
items: [
{ type: "text", name: "pypi", labelText: "PyPI 项目名" },
{ type: "text", name: "module", labelText: "适配器 import 包名" },
],
},
{
name: "其他信息",
items: [{ type: "tag", name: "tags", labelText: "标签" }],
},
];
const handleSubmit = (result: Record<string, string>) => {
window.open(
`https://github.com/nonebot/nonebot2/issues/new?${new URLSearchParams({
assignees: "",
labels: "Adapter",
projects: "",
template: "adapter_publish.yml",
title: `Adapter: ${result.name}`,
...result,
})}`
);
};

return (
<Form type="adapter" formItems={formItems} handleSubmit={handleSubmit} />
);
}
43 changes: 43 additions & 0 deletions website/src/components/Form/Bot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from "react";

import { Form } from ".";

export default function BotForm(): JSX.Element {
const formItems = [
{
name: "基本信息",
items: [
{
type: "text",
name: "name",
labelText: "机器人名称",
},
{ type: "text", name: "description", labelText: "机器人描述" },
{
type: "text",
name: "homepage",
labelText: "机器人项目仓库/主页链接",
},
],
},
{
name: "其他信息",
items: [{ type: "tag", name: "tags", labelText: "标签" }],
},
];

const handleSubmit = (result: Record<string, string>) => {
window.open(
`https://github.com/nonebot/nonebot2/issues/new?${new URLSearchParams({
assignees: "",
labels: "Bot",
projects: "",
template: "bot_publish.yml",
title: `Bot: ${result.name}`,
...result,
})}`
);
};

return <Form type="bot" formItems={formItems} handleSubmit={handleSubmit} />;
}
110 changes: 110 additions & 0 deletions website/src/components/Form/Items/Tag/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import React, { useState } from "react";

import clsx from "clsx";

import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { ChromePicker, type ColorResult } from "react-color";

import "./styles.css";

import TagComponent from "@/components/Tag";
import { Tag as TagType } from "@/types/tag";

export type Props = {
allowTags: TagType[];
onTagUpdate: (tags: TagType[]) => void;
};

export default function TagFormItem({
allowTags,
onTagUpdate,
}: Props): JSX.Element {
const [tags, setTags] = useState<TagType[]>([]);
const [label, setLabel] = useState<TagType["label"]>("");
const [color, setColor] = useState<TagType["color"]>("#ea5252");
const slicedTags = Array.from(
new Set(
allowTags
.filter((tag) => tag.label.toLocaleLowerCase().includes(label))
.map((e) => e.label)
)
).slice(0, 5);

const validateTag = () => {
return label.length >= 1 && label.length <= 10;
};
const newTag = () => {
if (tags.length >= 3) {
return;
}
if (validateTag()) {
const tag: TagType = { label, color };
setTags([...tags, tag]);
onTagUpdate(tags);
}
};
const delTag = (index: number) => {
setTags(tags.filter((_, i) => i !== index));
onTagUpdate(tags);
};
const onChangeColor = (color: ColorResult) => {
setColor(color.hex as TagType["color"]);
};

return (
<>
<label className="flex flex-wrap gap-x-1 gap-y-1">
{tags.map((tag, index) => (
<TagComponent
key={index}
{...tag}
className="cursor-pointer"
onClick={() => delTag(index)}
/>
))}
{tags.length < 3 && (
<span
className={clsx("add-btn", { "add-btn-disabled": !validateTag() })}
onClick={() => newTag()}
>
<FontAwesomeIcon className="pr-1" icon={["fas", "plus"]} />
新建标签
</span>
)}
</label>
<div className="form-item-container">
<span className="form-item-title">标签名称</span>
<div className="dropdown dropdown-bottom w-full">
<input
type="text"
value={label}
className="form-item form-item-input"
placeholder="请输入"
onChange={(e) => setLabel(e.target.value)}
/>
{slicedTags.length > 0 && (
<ul
tabIndex={0}
className="dropdown-content z-10 menu p-2 shadow bg-base-100 rounded-box w-52"
>
{slicedTags.map((tag) => (
<li key={tag}>
<a onClick={() => setLabel(tag)}>{tag}</a>
</li>
))}
</ul>
)}
</div>
</div>
<div className="form-item-container">
<span className="form-item-title">标签颜色</span>
<ChromePicker
className="my-4 fix-input-color"
color={color}
disableAlpha={true}
onChangeComplete={onChangeColor}
/>
</div>
</>
);
}
35 changes: 35 additions & 0 deletions website/src/components/Form/Items/Tag/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.add-btn {
@apply px-2 select-none cursor-pointer min-w-[64px] rounded-full hover:bg-opacity-[.08];
@apply flex justify-center items-center border-dashed border-2;

&-disabled {
@apply pointer-events-none opacity-60;
}
}

.form-item {
@apply basis-3/4;

&-title {
@apply basis-1/4 label-text;
}

&-input {
@apply input input-sm input-bordered;
}

&-select {
@apply select select-sm select-bordered;
}

&-container {
@apply flex items-center mt-2;
}
}

.fix-input-color {
@apply !text-base-content !bg-base-100;
input {
@apply !text-base-content !bg-base-100;
}
}
35 changes: 35 additions & 0 deletions website/src/components/Form/Plugin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from "react";

import { Form } from ".";

export default function PluginForm(): JSX.Element {
const formItems = [
{
name: "包信息",
items: [
{ type: "text", name: "pypi", labelText: "PyPI 项目名" },
{ type: "text", name: "module", labelText: "插件 import 包名" },
],
},
{
name: "其他信息",
items: [{ type: "tag", name: "tags", labelText: "标签" }],
},
];
const handleSubmit = (result: Record<string, string>) => {
window.open(
`https://github.com/nonebot/nonebot2/issues/new?${new URLSearchParams({
assignees: "",
labels: "Plugin",
projects: "",
template: "plugin_publish.yml",
title: `Plugin: ${result.pypi}`,
...result,
})}`
);
};

return (
<Form type="plugin" formItems={formItems} handleSubmit={handleSubmit} />
);
}
Loading
Loading