question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FR] Public styles API for existing components

See original GitHub issue

Is your feature request related to a problem? Please describe. Hey, I always prefer to use component libraries such hope-ui, and in a case when an ecosystem isn’t mature, like now with solid-js, I faced an issue with the deep styling of third-party libraries.

Let’s describe an example with code:

const MyComponent = (props) => {
  // some logic
  return (
    <Box>
       <Heading>Format your text!</Heading>
       {* A third-party rich text editor *}
       <TextEditor {...props} />
     </Box>
  )
}

In that case, I can’t apply hope-ui styles to inner buttons, because they are deeply nested. Of course I can write something like:

const MyComponent = (props) => {
  // some logic
  return (
    <Box css={{
        '& button': {
            color: '$primary2',
            //.....
        }
     }}>
       <Heading>Format your text!</Heading>
       {* A third-party rich text editor *}
       <TextEditor {...props} />
     </Box>
  )
}

but this means that I should rewrite all styles from scratch using theme variables to keep design consistency

Describe the solution you’d like The simple solution will be to export styles from existing barrels like this https://github.com/fabien-ml/hope-ui/blob/main/packages/solid/src/components/button/button.styles.ts

and our previous example could look like this:

import { buttonStyles } from '@hope-ui/core'

const MyComponent = (props) => {
  // some logic
  return (
    <Box css={{
        '& button': buttonStyles,
     }}>
       <Heading>Format your text!</Heading>
       {* A third-party rich text editor *}
       <TextEditor {...props} />
     </Box>
  )
}

Describe alternatives you’ve considered The alternative way is to apply CSS presets in global styles but this will decrease flexibility

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
fabien-mlcommented, Apr 19, 2022

@Miruzz i’ve published the v0.4.3 which export the styles. It’s available over the next tag on npm. I’ll switch it to latest after the end of the SolidJS hackathon voting period.

1reaction
Miruzzcommented, Apr 19, 2022

Such great news! I’ll wait then and meanwhile play a bit with the library. BTW my star is for you ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add style from props to existing component styles in React ...
React native will use StyleSheet.flatten to combine two object to be one style instance. This is the same: const newStyle = StyleSheet.flatten ...
Read more >
[Complete] RFC: Standalone APIs · Discussion #45554
This RFC complements that first proposal, and explores how standalone components will be integrated into Angular's API surface to achieve the ...
Read more >
Styles | API | Mapbox
The Mapbox Styles API lets you read and change map styles, fonts, and images. ... Public styles may be requested with an access...
Read more >
What is an Application Programming Interface (API)?
An application programming interface, or API, enables companies to open up their applications' data and functionality to external third-party developers, ...
Read more >
What are the types of APIs and their differences?
There are four principal types of API commonly used in web-based applications: public, partner, private and composite. In this context, the API ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found