Skip to content

Conversation

@Innei
Copy link
Member

@Innei Innei commented Dec 30, 2025

  • Refactor FlexBasic component into a web component, FlexBasicElement, with shadow DOM support.
  • Introduce CSS variables for flexible styling and layout management.
  • Update index to export new web component and its definition function.
  • Remove legacy FlexBasic implementation from FlexBasic.tsx.

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

🔀 变更说明 | Description of Change

📝 补充信息 | Additional Information

Summary by Sourcery

Migrate the FlexBasic layout component to a custom web component backed by a shadow-DOM-based HTMLElement implementation and update exports accordingly.

New Features:

  • Introduce a FlexBasicElement custom element with CSS-variable-driven flex layout and visibility control.
  • Expose utilities to define and use the FlexBasic web component from the Flex module, including a native element alias.

Enhancements:

  • Replace the legacy React FlexBasic functional component with the new web component implementation while preserving the existing FlexBasic export surface.
  • Extend global type declarations to support raw CSS imports in the build environment.

- Refactor FlexBasic component into a web component, FlexBasicElement, with shadow DOM support.
- Introduce CSS variables for flexible styling and layout management.
- Update index to export new web component and its definition function.
- Remove legacy FlexBasic implementation from FlexBasic.tsx.

Signed-off-by: Innei <[email protected]>
@vercel
Copy link

vercel bot commented Dec 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
lobe-ui Ready Ready Preview, Comment Dec 30, 2025 1:55pm

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 30, 2025

Reviewer's Guide

Replaces the React-based FlexBasic component with a custom element implementation (FlexBasicElement) backed by a shadow-DOM-based web component, wiring all previous layout props through attributes and CSS custom properties, and updates exports and global typing to support the new element and Vite raw CSS imports.

Sequence diagram for defining and using FlexBasicElement

sequenceDiagram
  actor Developer
  participant ReactApp
  participant Browser
  participant CustomElementsRegistry as customElements
  participant FlexBasicElement

  Developer->>ReactApp: Import FlexBasic (NativeFlexBasicElement)
  ReactApp->>Browser: Render <lobe-flex ...> in DOM
  Note over Browser,CustomElementsRegistry: defineFlexBasicElement() has registered lobe-flex
  Browser->>CustomElementsRegistry: Lookup constructor for tag lobe-flex
  CustomElementsRegistry-->>Browser: FlexBasicElement
  Browser->>FlexBasicElement: new FlexBasicElement() and connectedCallback()
  FlexBasicElement->>FlexBasicElement: attachShadow({mode:open})
  FlexBasicElement->>FlexBasicElement: create style, hostStyle, container, slot
  FlexBasicElement->>FlexBasicElement: #sync() apply CSS vars and classes

  Developer->>ReactApp: Update props on FlexBasic
  ReactApp->>Browser: Update attributes on <lobe-flex>
  Browser->>FlexBasicElement: attributeChangedCallback()
  FlexBasicElement->>FlexBasicElement: #sync() recompute layout CSS variables
Loading

Class diagram for FlexBasicElement web component implementation

classDiagram
  class HTMLElement

  class FlexBasicProps

  class FlexBasicElement {
    +static AttrName[] observedAttributes
    -ShadowRoot #shadow
    -HTMLDivElement #container
    +connectedCallback() void
    +attributeChangedCallback() void
    -#sync() void
  }

  class Utils {
    +getCssValue(value)
    +getFlexDirection(direction, horizontal)
    +isHorizontal(direction, horizontal)
    +isSpaceDistribution(justifyContent)
  }

  class AttributeParsers {
    +parseBooleanAttr(value) boolean
    +parseMaybeNumber(value) number|string
    +readStringAttr(value) string
  }

  class FlexBasicExports {
    +defineFlexBasicElement(tagName) void
    +NativeFlexBasicElement FC_FlexBasicProps
  }

  FlexBasicElement --|> HTMLElement
  FlexBasicElement ..> FlexBasicProps
  FlexBasicElement ..> Utils
  FlexBasicElement ..> AttributeParsers
  FlexBasicExports ..> FlexBasicElement
  FlexBasicExports ..> FlexBasicProps
Loading

File-Level Changes

Change Details Files
Replace React FlexBasic FC with a web component-backed implementation and re-export it as the default FlexBasic.
  • Remove the React FlexBasic functional component implementation and memoization, keeping only an export that re-exports NativeFlexBasicElement as the default.
  • Ensure the new default still satisfies the FlexBasicProps typing by aliasing the custom element tag string to a React FC type.
src/Flex/FlexBasic.tsx
Introduce FlexBasicElement custom element with shadow DOM, internal layout logic, and CSS custom-property-driven styling.
  • Define FlexBasicElement extending HTMLElement with shadow DOM setup, internal container div, and slot for light DOM children.
  • Port previous flex layout logic to attribute-based configuration, including direction, horizontal detection, space distribution width logic, and visibility handling.
  • Manage CSS custom properties such as --lobe-flex, --lobe-flex-direction, padding, gap, width/height, and prefix-based class names, resetting them when attributes are removed.
  • Auto-define the custom element (defineFlexBasicElement) under the lobe-flex tag and export both the element class and a NativeFlexBasicElement React-typed alias.
src/Flex/FlexBasic.web.ts
Expose the new web component APIs through the Flex module entrypoint.
  • Export defineFlexBasicElement, FlexBasicElement, and NativeFlexBasicElement from the Flex index file alongside existing components.
src/Flex/index.ts
Augment global typing to support Vite ?raw CSS imports needed by web components or future styling work.
  • Add a module declaration for '*.css?raw' returning string content to the shared global TypeScript declarations.
src/types/global.d.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@lobehubbot
Copy link
Member

👍 @Innei


Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 30, 2025

Open in StackBlitz

npm i https://pkg.pr.new/lobehub/lobe-ui/@lobehub/ui@441

commit: d7985d8

- Refactor the FlexBasicElement class definition to be encapsulated within a `defineFlexBasicElement` function for better modularity.
- Maintain existing functionality while improving the structure for future enhancements.
- Ensure compatibility with custom elements and shadow DOM.

Signed-off-by: Innei <[email protected]>
…n logic

- Introduce global styles for lobe-flex elements to improve styling consistency.
- Refactor initialization logic to eliminate the use of shadow DOM, simplifying the component structure.
- Update class management to directly manipulate the element's class list, enhancing performance and readability.

Signed-off-by: Innei <[email protected]>
- Eliminate the global CSS styles for lobe-flex elements to streamline the component.
- Update the FlexBasicElement definition to focus on core functionality without injecting styles into the document.
- Prepare for future enhancements by simplifying the component structure.

Signed-off-by: Innei <[email protected]>
- Introduce tests for handling React-style camelCase and kebab-case attributes in the FlexBasic web component.
- Validate that attributes are correctly parsed and applied to the element's styles and class list.
- Ensure compatibility with custom elements in various environments.

Signed-off-by: Innei <[email protected]>
- Introduce ReactFlexBasic as a functional component to handle props and styles dynamically.
- Update FlexBasic to conditionally render either the native web component or the React implementation based on the 'as' prop.
- Enhance class management in FlexBasicElement to prevent clobbering existing class names, improving compatibility with frameworks like React.
- Add unit tests to ensure className integrity when connecting the custom element.

Signed-off-by: Innei <[email protected]>
…in Flexbox

- Refactor Center component to utilize AutoFlex for improved layout handling.
- Update Flexbox exports to default to AutoFlex, streamlining component usage.

Signed-off-by: Innei <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants