Procházet zdrojové kódy

[stdf]Update Icon compoent, demo and documents.

dufu1991 před 1 rokem
rodič
revize
7acb6f4603

+ 4 - 10
demo/src/routes/en_US/icon/+page.svelte

@@ -63,27 +63,22 @@
 	</div>
 	<div>
 		<div class="mb-2 font-bold text-xl">
-			Custom color<span class="ml-2 text-xs font-normal">by slot</span>
+			Custom color<span class="ml-2 text-xs font-normal">by Snippet</span>
 		</div>
 		<div class="flex flex-wrap justify-between">
 			{#each icons as icon}
 				<div class="py-2 text-center flex-1">
-					<Icon name="slot">
-						<i class="text-[#266CF6] dark:text-[#C84031]">
-							<Icon name={icon} />
-						</i>
-					</Icon>
+					<Icon><i class="text-[#266CF6] dark:text-[#C84031]"> <Icon name={icon} /></i></Icon>
 				</div>
 			{/each}
 		</div>
 	</div>
 	<div>
-		<div class="mb-2 font-bold text-xl">Slot</div>
+		<div class="mb-2 font-bold text-xl">Snippet</div>
 		<div class="flex flex-wrap justify-between">
-			<!-- eslint-disable-next-line no-unused-vars -->
 			{#each icons as icon, index}
 				<div class="py-2 text-center flex-1">
-					<Icon name="slot">
+					<Icon>
 						<svg
 							height="24"
 							width="24"
@@ -106,7 +101,6 @@
 	<div>
 		<div class="mb-2 font-bold text-xl">Offset</div>
 		<div class="flex flex-wrap justify-between">
-			<!-- eslint-disable-next-line no-unused-vars -->
 			{#each icons as icon, i}
 				<div class="py-2 text-center flex-1">
 					<Icon name={icons[1]} top={-4 + i * 2} />

+ 4 - 10
demo/src/routes/zh_CN/icon/+page.svelte

@@ -63,27 +63,22 @@
 	</div>
 	<div>
 		<div class="mb-2 font-bold text-xl">
-			自定义颜色<span class="ml-2 text-xs font-normal">通过 slot</span>
+			自定义颜色<span class="ml-2 text-xs font-normal">通过 Snippet</span>
 		</div>
 		<div class="flex flex-wrap justify-between">
 			{#each icons as icon}
 				<div class="py-2 text-center flex-1">
-					<Icon name="slot">
-						<i class="text-[#266CF6] dark:text-[#C84031]">
-							<Icon name={icon} />
-						</i>
-					</Icon>
+					<Icon><i class="text-[#266CF6] dark:text-[#C84031]"><Icon name={icon} /></i></Icon>
 				</div>
 			{/each}
 		</div>
 	</div>
 	<div>
-		<div class="mb-2 font-bold text-xl">插槽</div>
+		<div class="mb-2 font-bold text-xl">Snippet</div>
 		<div class="flex flex-wrap justify-between">
-			<!-- eslint-disable-next-line no-unused-vars -->
 			{#each icons as icon, index}
 				<div class="py-2 text-center flex-1">
-					<Icon name="slot">
+					<Icon>
 						<svg
 							height="24"
 							width="24"
@@ -106,7 +101,6 @@
 	<div>
 		<div class="mb-2 font-bold text-xl">偏移</div>
 		<div class="flex flex-wrap justify-between">
-			<!-- eslint-disable-next-line no-unused-vars -->
 			{#each icons as icon, i}
 				<div class="py-2 text-center flex-1">
 					<Icon name={icons[1]} top={-4 + i * 2} />

+ 13 - 19
doc/components/icon/api.md

@@ -1,23 +1,17 @@
 ## Icon Props
 
-| 属性     | 类型        | 默认值             | 可选值                | 必传 | 说明                             |
-| -------- | ----------- | ------------------ | --------------------- | ---- | -------------------------------- |
-| name     | String/slot | ''                 | SVG Sprites name/slot | Y    | 图标名称。                       |
-| size     | Number      | 24                 | -                     | N    | 图标大小。                       |
-| theme    | Boolean     | false              | true/false            | N    | 是否跟随主题色(包含亮暗模式)。 |
-| alpha    | Number      | 1                  | 0 - 1                 | N    | 图标透明度。                     |
-| top      | Number      | -2                 | -                     | N    | 上下偏移量。                     |
-| injClass | String      | ''                 | Class                 | N    | 注入 CSS 名称。                  |
-| path     | String      | 'fonts/symbol.svg' | -                     | N    | 项目存放 symbol.svg 的路径。     |
+| 名称     | 类型      | 默认值               | 必传 | 说明                             |
+| -------- | --------- | -------------------- | ---- | -------------------------------- |
+| name     | `string`  | `''`                 | N    | 图标名称。                       |
+| size     | `number`  | `24`                 | N    | 图标大小。                       |
+| theme    | `boolean` | `false`              | N    | 是否跟随主题色(包含亮暗模式)。 |
+| alpha    | `number`  | `1`                  | N    | 图标透明度。                     |
+| top      | `number`  | `0`                  | N    | 上下偏移量。                     |
+| injClass | `string`  | `''`                 | N    | 注入 CSS 名称。                  |
+| path     | `string`  | `'fonts/symbol.svg'` | N    | 项目存放 symbol.svg 的路径。     |
 
-## Icon Events
+## Icon Snippets
 
-| 名称  | 参数 | 描述       |
-| ----- | ---- | ---------- |
-| click | -    | 点击触发。 |
-
-## Icon Slots
-
-| 名称 | 说明         |
-| ---- | ------------ |
-| -    | 自定义 SVG。 |
+| 名称     | 说明                                      |
+| -------- | ----------------------------------------- |
+| children | 自定义内容,一般是 Icon 组件或 SVG 元素。 |

+ 13 - 19
doc/components/icon/api_en.md

@@ -1,23 +1,17 @@
 ## Icon Props
 
-| Properties | Type        | Default value      | Optional value        | required | Description                                                           |
-| ---------- | ----------- | ------------------ | --------------------- | -------- | --------------------------------------------------------------------- |
-| name       | String/slot | ''                 | SVG Sprites name/slot | Y        | Icon name.                                                            |
-| size       | Number      | 24                 | -                     | N        | Icon size.                                                            |
-| theme      | Boolean     | false              | true/false            | N        | Whether to follow the theme color (including bright and dark colors). |
-| alpha      | Number      | 1                  | 0 - 1                 | N        | Icon transparency.                                                    |
-| top        | Number      | -2                 | -                     | N        | Disposal up and down.                                                 |
-| injClass   | String      | ''                 | Class                 | N        | Inject the CSS name.                                                  |
-| path       | String      | 'fonts/symbol.svg' | -                     | N        | The project stores the path of symbol.svg.                            |
+| Name     | Type      | Default              | Required | Description                                      |
+| -------- | --------- | -------------------- | -------- | ------------------------------------------------ |
+| name     | `string`  | `''`                 | N        | Icon name.                                       |
+| size     | `number`  | `24`                 | N        | Icon size.                                       |
+| theme    | `boolean` | `false`              | N        | Whether to follow theme color (light/dark mode). |
+| alpha    | `number`  | `1`                  | N        | Icon opacity.                                    |
+| top      | `number`  | `0`                  | N        | Vertical offset.                                 |
+| injClass | `string`  | `''`                 | N        | Injected CSS class name.                         |
+| path     | `string`  | `'fonts/symbol.svg'` | N        | Project path for symbol.svg file.                |
 
-## Icon Events
+## Icon Snippets
 
-| Name  | Parameter | Description       |
-| ----- | --------- | ----------------- |
-| click | -         | Click to trigger. |
-
-## Icon Slots
-
-| Name | Description |
-| ---- | ----------- |
-| -    | Custom SVG. |
+| Name     | Description                                            |
+| -------- | ------------------------------------------------------ |
+| children | Custom content, usually Icon component or SVG element. |

+ 4 - 4
doc/components/icon/guide.md

@@ -26,7 +26,7 @@ STDF 部分组件内使用的图标源自 [Remix Icon 图标库](https://remixic
 
 ## 图标名称
 
-name 为 'slot' 表示使用插槽渲染,其他字符如 'ri-home-line' 使用 symbol.svg 中对应的 SVG 图标渲染。
+当传入 Snippet 时表示图标内部使用传入的元素渲染,其他字符如 'ri-home-line' 使用 symbol.svg 中对应的 SVG 图标渲染。
 
 ## 图标颜色
 
@@ -34,7 +34,7 @@ name 为 'slot' 表示使用插槽渲染,其他字符如 'ri-home-line' 使用
 
 ## 颜色优先级
 
-颜色优先级 slot > injClass > theme > 默认。
+颜色优先级 Snippet > injClass > theme > 默认。
 
 ## 偏移量
 
@@ -44,6 +44,6 @@ name 为 'slot' 表示使用插槽渲染,其他字符如 'ri-home-line' 使用
 
 通过 injClass 参数可以向组件内部最外层元素注入 CSS 名称(不仅限于 Tailwind CSS),这将使组件样式有更多自定义可能性。因为 CSS 注入于最后,此时最外层元素若已有同属性 CSS 将会以 injClass 为准,这也是通过 injClass 实现自定义图标颜色的原因。
 
-## 插槽
+## Snippet
 
-可放入任何元素(甚至 Icon 组件自身),当然主要用于自定义图标或自定义图标颜色,如将自定义 SVG 放入 Icon 组件,请注意 SVG 的 viewBox、height、width 关系与 display 属性。此时图标内容取决于传入的元素,Props 中的 name、size、theme 等参数都将失效。通过插槽将使组件内容有更多自定义可能性。
+可放入任何元素(甚至 Icon 组件自身),当然主要用于自定义图标或自定义图标颜色,如将自定义 SVG 放入 Icon 组件,请注意 SVG 的 viewBox、height、width 关系与 display 属性。此时图标内容取决于传入的元素,Props 中的 name、size、theme 等参数都将失效。通过 Snippet 将使组件内容有更多自定义可能性。

+ 20 - 20
doc/components/icon/guide_en.md

@@ -1,49 +1,49 @@
 ## Background
 
-STDF uses SVG Sprites technology for icons, which helps reduce HTTP requests and improve page performance.
+STDF uses SVG Sprites technology for icons, which reduces HTTP requests and improves page performance.
 
-STDF's SVG Sprites use [SVG symbol](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol), which is similar to CSS Sprite technique. It combines SVG files in the project into a single file and uses the `<use>` element in SVG to display the corresponding icons.
+STDF's SVG Sprites uses [SVG symbol](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol), with a principle similar to CSS Sprite technology - combining project SVG files into one file and displaying icons through the SVG use element.
 
-You can think of it as a type of font, except that it is composed of SVG and can be styled using CSS properties such as color and size. Therefore, for larger or more complex icons with multiple colors, it is recommended to use individual SVG files instead of placing them in the symbol.
+You can think of it as a font, except it's composed of SVGs and can be styled with CSS properties like color and size. For large or complex icons with multiple colors, it's recommended to import SVG files separately rather than including them in the symbol.
 
-Compatibility is not an issue. Refer to [MDN symbol](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol#browser_compatibility) for more information.
+Browser compatibility is not an issue. See [MDN symbol](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol#browser_compatibility).
 
 ## rollup-plugin-stdf-icon
 
-STDF has developed a Rollup/Vite plugin called rollup-plugin-stdf-icon, which combines SVG files in the project into SVG Sprites. Please refer to [rollup-plugin-stdf-icon](https://www.npmjs.com/package/rollup-plugin-stdf-icon) for specific usage. Due to the diversity of SVG formats, there may be cases where rollup-plugin-stdf-icon does not handle them accurately. In such cases, please raise an issue on [GitHub](https://github.com/any-tdf/stdf/issues) and provide details about the SVG file.
+STDF has developed a Rollup/Vite plugin to merge SVG files into SVG Sprites. For usage details, see [rollup-plugin-stdf-icon](https://www.npmjs.com/package/rollup-plugin-stdf-icon). Due to SVG format variations, if you encounter any issues with rollup-plugin-stdf-icon processing, please submit an issue on [GitHub](https://github.com/any-tdf/stdf/issues) with specific SVG file details.
 
-Alternatively, you can use other SVG Sprites synthesis tools or manually combine them. You can also ask the designer to provide the corresponding SVG Sprites along with the design materials.Or, for icon libraries like Remix Icon, you can directly download a selection of multiple icons as SVG Sprites.
+You can also use other SVG Sprites generation tools, manual compilation, or request SVG Sprites from designers along with design assets. Icon libraries like Remix Icon allow direct download of selected icons as SVG Sprites.
 
 ## Built-in Icons
 
-Some of the icons used in STDF components are sourced from [Remix Icon Library](https://remixicon.com) ([GitHub](https://github.com/Remix-Design/remixicon)). Many thanks to them! 🙏🏻🙏🏻
+Some STDF components use icons from [Remix Icon](https://remixicon.com) ([GitHub](https://github.com/Remix-Design/remixicon)). We express our gratitude 🙏🏻🙏🏻.
 
-**If you are using these components, please make sure that the `symbol.svg` file in your project includes the corresponding icons.**
+**When using these components, ensure your project's symbol.svg includes the corresponding icons.**
 
-Please refer to [STDF-Guide-Icon](https://stdf.design/#/guide/icon) for details.
+For details, refer to [STDF-Guide-Icon](https://stdf.design/#/guide/icon).
 
-You can find the SVG source files for these icons in `node_modules/stdf/assets/svg_base/`.
+You can find SVG source files in `node_modules/stdf/assets/svg_base/`.
 
-## Icon Name
+## Icon Names
 
-If the `name` is `'slot'`, use a slot to render, otherwise use the corresponding SVG icon in `symbol.svg` to render.
+When a Snippet is passed, the icon renders using the passed element. Other strings like 'ri-home-line' render the corresponding SVG icon from symbol.svg.
 
-## Icon Color
+## Icon Colors
 
-If `theme` is not passed or passed in as `false`, the icon color will inherit the parent's text color. If `true` is passed, the icon color will change according to the theme (including light and dark modes). If you want to achieve a custom color and the color includes both light and dark modes, it is recommended to use CSS injection or slot rendering, and configure the light and dark colors in `injClass` or slots separately. Please refer to the example.
+Without theme prop or when set to false, icons inherit parent text color. When true, icons follow theme colors (including light/dark modes). For custom colors with light/dark mode support, use CSS injection or slot rendering with injClass or slots configured for both modes. See examples.
 
 ## Color Priority
 
-Color priority: slot > injClass > theme > default.
+Color priority: Snippet > injClass > theme > default.
 
-## Offset
+## Vertical Offset
 
-In European and West Asian typesetting, there is a baseline, but there is no baseline in East Asian typesetting, refer to [MDN](https://developer.mozilla.org/en-US/docs/Glossary/baseline). However, due to differences in fonts in different systems, it may cause misalignment when icons are arranged together with text. Adjust the offset to fine-tune these alignments. Or, for some icons, due to differences in visual gravity, an offset is required when laying out to maintain visual balance.
+European and West Asian typography has a baseline, while East Asian text doesn't. See [MDN](https://developer.mozilla.org/zh-CN/docs/Glossary/baseline). Due to differences in system fonts, icons may misalign with text. Use the offset to fine-tune alignment or balance visual weight of icons.
 
 ## CSS Injection
 
-The `injClass` parameter can be used to inject a CSS class name (not limited to Tailwind CSS) into the outermost element of the component, which will give the component more customizability in terms of style. Because CSS injection comes last, if there are existing CSS properties on the outermost element, `injClass` will override them. This is also the reason for using `injClass` to customize the icon color.
+The injClass parameter injects CSS classes (not limited to Tailwind CSS) into the component's outer element, enabling more style customization. Since CSS injection occurs last, any existing CSS properties on the outer element will be overridden by injClass, which enables custom icon colors.
 
-## Slot
+## Snippet
 
-Any element can be inserted (even the Icon component itself), but mainly used for customizing icons or icon colors, such as inserting custom SVGs into the Icon component. Please note the relationship between the viewBox, height, and width of the SVG and the display property. The icon content depends on the element passed in. The parameters such as name, size, and theme in Props will be invalid. The slot will give the component more customizability in terms of content.
+Can contain any element (even Icon component itself), primarily used for custom icons or colors. When placing custom SVGs in Icon component, note the relationships between SVG viewBox, height, width, and display property. Icon content depends on the passed element, and Props like name, size, theme become ineffective. Snippets enable more customization possibilities for component content.

+ 2 - 4
packages/stdf/components/icon/Icon.svelte

@@ -5,10 +5,8 @@
 </script>
 
 <i class={`cursor-pointer relative ${theme ? 'text-primary dark:text-dark' : ''} ${injClass}`} style="top:{top}px;">
-	{#if name === 'slot'}
-		{#if children}
-			{@render children()}
-		{/if}
+	{#if children}
+		{@render children()}
 	{:else}
 		<svg width={size} height={size === 'full' ? '100%' : size} style="fill: currentColor;fill-opacity: {alpha};display: inline;">
 			<use xlink:href="/{path}#{name}" />