Skip to content

feat(config-provider): config-provider adds theme configuration function #3353

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

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Apr 25, 2025

config-provider添加配置主题功能

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Added a new theme property to the configuration provider component, enabling users to customize theme colors dynamically.
    • Introduced new demos and examples illustrating how to use the theme property for theme customization.
    • Added a swipeable property to the tabs component, allowing users to enable swipe-based tab switching on mobile.
    • Provided a new demo showcasing swipeable tab content for mobile interfaces.
  • Documentation

    • Updated and expanded documentation to include new properties and usage examples for theme customization and swipeable tabs.

Copy link

coderabbitai bot commented Apr 25, 2025

Walkthrough

This update introduces customizable theme support and swipeable tabs to the component library. A new theme prop is added to the config provider, enabling dynamic theme color changes via an object with a data property. Supporting demos and documentation are provided for both options and composition API usage. Additionally, the tabs component now accepts a swipeable boolean prop in mobile-first mode, demonstrated with a new swipeable tab interface and corresponding documentation. Utility enhancements include a new hasAnyKey function and updated dependencies to facilitate these features.

Changes

File(s) Change Summary
examples/sites/demos/apis/config-provider.js, packages/vue/src/config-provider/src/props.ts Added theme prop to config provider component and its type/interface definition.
packages/vue/src/config-provider/src/index.vue Implemented theme prop handling: watches for changes, validates structure, applies theme via TinyThemeTool.
examples/sites/demos/pc/app/config-provider/theme.vue, theme-composition-api.vue Added new Vue demos showing theme switching via options API and composition API.
examples/sites/demos/pc/app/config-provider/webdoc/config-provider.js Documented new theme demo with bilingual descriptions and code reference.
packages/utils/src/common/index.ts Added utility function hasAnyKey to check for presence of specified keys in an object.
packages/vue/src/config-provider/package.json Added @opentiny/utils as a dependency.
examples/sites/demos/apis/tabs.js Introduced swipeable boolean prop to tabs component for mobile-first mode.
examples/sites/demos/mobile-first/app/tabs/swipeable.vue New Vue demo component implementing swipeable tabs with horizontal scrolling content.
examples/sites/demos/mobile-first/app/tabs/webdoc/tabs.js Documented new swipeable tabs demo with bilingual descriptions and code reference.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ConfigProvider
  participant TinyThemeTool

  User->>ConfigProvider: Set theme prop (object with data)
  ConfigProvider->>ConfigProvider: Watch theme prop
  alt theme is object with data
    ConfigProvider->>TinyThemeTool: changeTheme(theme)
  else theme missing data key
    ConfigProvider->>User: Console warning (missing data property)
  else theme not object
    ConfigProvider->>User: Console warning (theme must be object)
  end
Loading
sequenceDiagram
  participant User
  participant TabsComponent

  User->>TabsComponent: Enable swipeable prop (mobile-first)
  TabsComponent->>TabsComponent: Render tabs with swipe gestures enabled
  User->>TabsComponent: Swipe tab content area
  TabsComponent->>TabsComponent: Switch active tab on swipe
Loading

Poem

In the garden of code, new colors bloom bright,
With themes you can swap from dark into light.
Tabs now can swipe with a flick and a slide,
While rabbits with joy in the UI reside.
Utilities grow, and docs keep in sync—
Hop along, dear dev, to the future in a blink!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/sites/demos/apis/tabs.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

examples/sites/demos/apis/config-provider.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

examples/sites/demos/mobile-first/app/tabs/webdoc/tabs.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 7 others
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the enhancement New feature or request (功能增强) label Apr 25, 2025
Copy link

Walkthrough: This PR introduces a new theme configuration feature to the config-provider component in the Tiny Vue library. It allows users to customize theme colors using a specified format. Additionally, a swipeable feature is added to tabs, enabling sliding content switching.

Changes:

File(s) Summary
examples/sites/demos/apis/config-provider.js Added theme configuration option with customization details.
examples/sites/demos/apis/tabs.js Introduced swipeable feature for tabs.
examples/sites/demos/mobile-first/app/tabs/swipeable.vue New demo for swipeable tabs feature.
examples/sites/demos/mobile-first/app/tabs/webdoc/tabs.js Documentation for swipeable tabs feature.
examples/sites/demos/pc/app/config-provider/theme-composition-api.vue New demo for theme customization using composition API.
examples/sites/demos/pc/app/config-provider/theme.vue New demo for theme customization.
examples/sites/demos/pc/app/config-provider/webdoc/config-provider.js Documentation for theme customization feature.
packages/theme-saas/src/svgs/go-back.svg Minor SVG changes.
packages/utils/src/common/index.ts Added utility function to check for keys in an object.
packages/vue/src/config-provider/package.json Updated package dependencies.
packages/vue/src/config-provider/src/index.vue Integrated theme configuration logic.
packages/vue/src/config-provider/src/props.ts Added theme property to props.

}

if (isObject(theme.value) && !hasAnyKey(theme.value, ['data'])) {
console.warn(`configProvider组件的theme属性对象请配置data属性。e.g { data: {'tv-base-color-brand': '#000'}}`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning message here should be more descriptive to guide the user on how to properly configure the theme property. Consider providing a more detailed example or linking to documentation.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (8)
examples/sites/demos/pc/app/config-provider/theme-composition-api.vue (2)

15-17: Consider initializing theme with default values

The initial theme object has an empty data property. Consider initializing it with default values to make the initial state more explicit.

const theme = ref({
-  data: {}
+  data: {
+    'tv-base-color-brand': '#191919'
+  }
})

36-41: Add more documentation for CSS selectors

The CSS selectors target .tiny-config-provider which is applied by the component, but it's not immediately clear to users. Consider adding a comment to explain this relationship.

<style scoped>
+/* Styles applied to the TinyConfigProvider component for demonstration purposes */
.tiny-config-provider {
  padding: 1em;
  border: 1px solid #ccc;
  border-radius: 1em;
}
</style>
packages/vue/src/config-provider/src/index.vue (3)

10-32: Consider moving hasAnyKey to a utility file

The hasAnyKey utility function is well-implemented but would be better placed in a shared utility file since it's a generic function that could be useful elsewhere.

Consider moving this function to your utilities and importing it instead:

-/**
- * 检查对象是否具有任何一个指定的键
- * @param obj 需要检查的对象
- * @param keys 需要检查的键的数组
- * @return 如果对象具有任何一个指定的键,返回true,否则返回false
- */
-const hasAnyKey = (obj: any, keys: string[]): boolean => {
-  if (obj == null) {
-    return false
-  }
-
-  if (keys.length === 0) {
-    return false
-  }
-
-  for (const key of keys) {
-    if (Object.prototype.hasOwnProperty.call(obj, key)) {
-      return true
-    }
-  }
-
-  return false
-}
+import { hasAnyKey } from '@opentiny/utils'

98-101: Consider prefetching theme tool

Creating a new instance of TinyThemeTool on every theme change might be inefficient. Consider creating it once and reusing it.

+const themeTool = new TinyThemeTool()
 hooks.watch(
   () => theme.value,
   () => {
     if (isObject(theme.value) && hasAnyKey(theme.value, ['data'])) {
-      const themeTool = new TinyThemeTool()
       themeTool.changeTheme(theme.value)
     }

103-109: Enhance warning messages with examples

Your warning messages are helpful, but adding code examples would make them even more useful.

-console.warn(`configProvider组件的theme属性对象请配置data属性。e.g { data: {'tv-base-color-brand': '#000'}}`)
+console.warn(`configProvider组件的theme属性对象请配置data属性。例如: { data: {'tv-base-color-brand': '#000'} }`)

-console.warn(`configProvider组件的theme属性请配置对象格式数据`)
+console.warn(`configProvider组件的theme属性请配置对象格式数据, 例如: { data: { 'tv-base-color-brand': '#000' } }`)
examples/sites/demos/pc/app/config-provider/theme.vue (2)

21-23: Consider initializing theme with default values

The initial theme object has an empty data property. Consider initializing it with default values to make the initial state more explicit.

theme: {
-  data: {}
+  data: {
+    'tv-base-color-brand': '#191919'
+  }
}

46-50: Add more documentation for CSS selectors

The CSS selectors target .tiny-config-provider which is applied by the component, but it's not immediately clear to users. Consider adding a comment to explain this relationship.

<style scoped>
+/* Styles applied to the TinyConfigProvider component for demonstration purposes */
.tiny-config-provider {
  padding: 1em;
  border: 1px solid #ccc;
  border-radius: 1em;
}
</style>
examples/sites/demos/apis/config-provider.js (1)

50-51: Fix English documentation format

There's a small format issue in the English description of the theme property.

desc: {
  'zh-CN': '自定义主题色,格式:{data:{"tv-base-color-brand":"#595959",....}}',
-  'en-US': 'Customized theme color, in {data:"tv-base-color-brand":"#595959",....} format.'
+  'en-US': 'Customized theme color, in {data:{"tv-base-color-brand":"#595959",....}} format.'
},
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe9c01c and 37349a0.

⛔ Files ignored due to path filters (1)
  • packages/theme-saas/src/svgs/go-back.svg is excluded by !**/*.svg
📒 Files selected for processing (11)
  • examples/sites/demos/apis/config-provider.js (1 hunks)
  • examples/sites/demos/apis/tabs.js (1 hunks)
  • examples/sites/demos/mobile-first/app/tabs/swipeable.vue (1 hunks)
  • examples/sites/demos/mobile-first/app/tabs/webdoc/tabs.js (1 hunks)
  • examples/sites/demos/pc/app/config-provider/theme-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/config-provider/theme.vue (1 hunks)
  • examples/sites/demos/pc/app/config-provider/webdoc/config-provider.js (1 hunks)
  • packages/utils/src/common/index.ts (1 hunks)
  • packages/vue/src/config-provider/package.json (1 hunks)
  • packages/vue/src/config-provider/src/index.vue (3 hunks)
  • packages/vue/src/config-provider/src/props.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/vue/src/config-provider/src/props.ts

[error] 23-23: Don't use 'Object' as a type.

Prefer explicitly define the object shape. This type means "any non-nullable value", which is slightly better than 'unknown', but it's still a broad type.

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (13)
examples/sites/demos/apis/tabs.js (1)

141-151: Looks good - new swipeable property well-documented

The new swipeable boolean property is added with clear descriptions in both Chinese and English, consistent default value, and correctly specifies mobile-first mode only. The property documentation follows the existing structure pattern.

examples/sites/demos/mobile-first/app/tabs/webdoc/tabs.js (1)

32-44: New swipeable demo entry properly structured

The demo entry for the swipeable tabs feature is well-structured with bilingual names and descriptions that accurately explain the feature's requirements (disabled optimization and lazy loading). The code references the correct implementation file.

examples/sites/demos/mobile-first/app/tabs/swipeable.vue (2)

1-34: Well-implemented swipeable tabs template

The template correctly implements the swipeable feature by:

  1. Disabling optimization with :optimized="false" as required
  2. Enabling the swipeable mode with the swipeable attribute
  3. Creating a good demonstration with horizontally scrollable content in the first tab

The class select-none is a good addition to prevent text selection during swipe gestures.


36-50: Component implementation follows Vue best practices

The component correctly imports and registers the necessary components from @opentiny/vue and manages tab state through reactive data. The implementation is clean and follows Vue best practices.

packages/utils/src/common/index.ts (1)

312-334: Well-implemented utility function for checking object keys.

The hasAnyKey function provides a useful utility to check if an object contains at least one key from a given array. The implementation correctly handles edge cases:

  • Null/undefined objects
  • Empty key arrays
  • Safe property checking using Object.prototype.hasOwnProperty.call

The function is also well-documented with clear JSDoc comments explaining its purpose and parameters.

packages/vue/src/config-provider/package.json (1)

18-19: Appropriate dependency addition for theme functionality.

Adding the @opentiny/utils dependency is correctly aligned with the new theme customization feature, as it will provide access to the newly added hasAnyKey utility function used for theme object validation.

examples/sites/demos/pc/app/config-provider/webdoc/config-provider.js (1)

47-57: Good documentation for the new theme customization feature.

The new demo entry for theme customization is well-structured with bilingual support and clear descriptions of the functionality. This properly documents the new theme property added to the config-provider component.

examples/sites/demos/pc/app/config-provider/theme-composition-api.vue (1)

1-43: Well-structured composition API example for theme demonstration

This is a clear demonstration of the new theme configuration feature using Vue's composition API. The code is well-organized with reactive theme management and two theme-switching functions.

packages/vue/src/config-provider/src/index.vue (3)

7-8: The new imports look good

Properly importing the required dependencies for theme functionality.


71-76: Theme prop definition looks good

The theme prop is properly defined as an object with null default.


93-114: Well-implemented theme functionality with validations

Good job implementing the theme functionality with proper validation and error handling. The warnings provide helpful guidance to users when they provide invalid values.

examples/sites/demos/pc/app/config-provider/theme.vue (1)

1-52: Well-structured options API example for theme demonstration

This is a clear demonstration of the new theme configuration feature using Vue's options API. The code is well-organized with a reactive theme object and methods to change themes.

examples/sites/demos/apis/config-provider.js (1)

42-55: Well-documented theme property

The API documentation for the new theme property is comprehensive, including type, default value, stability information, descriptions in multiple languages, and a demo reference.

@@ -20,4 +20,5 @@ export interface ConfigProviderProps {
enable?: boolean
name?: string
}
theme?: Object | null
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid using Object as a type and define a specific interface instead.

Using Object as a type is overly broad and provides little type safety. Consider creating a specific interface that defines the expected structure of the theme object, which would provide better documentation and type checking.

+ export interface ThemeConfig {
+   data: Record<string, string>;
+   // Add any other expected properties
+ }

export interface ConfigProviderProps {
  breakPoints: breakPoint
  direction: 'rtl' | 'ltr'
  globalPrefix?: string
  tag: {
    enable?: boolean
    name?: string
  }
-  theme?: Object | null
+  theme?: ThemeConfig | null
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
theme?: Object | null
export interface ThemeConfig {
data: Record<string, string>
// Add any other expected properties
}
export interface ConfigProviderProps {
breakPoints: breakPoint
direction: 'rtl' | 'ltr'
globalPrefix?: string
tag: {
enable?: boolean
name?: string
}
theme?: ThemeConfig | null
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 23-23: Don't use 'Object' as a type.

Prefer explicitly define the object shape. This type means "any non-nullable value", which is slightly better than 'unknown', but it's still a broad type.

(lint/complexity/noBannedTypes)

@zzcr zzcr merged commit 5c9f4e3 into dev Apr 25, 2025
12 of 16 checks passed
@zzcr zzcr deleted the sync-to-dev-0425 branch April 25, 2025 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request (功能增强)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant