Comments (4)
@Tropix126 Yep, I get your point but I find style attribute to be quite useful sometime. Let's keep it that way and thank for the explanation about component styling.
Do you think it should be added in the docs?
I eventually plan to add a page explaining some common patterns across different components, including the behavior of $$restProps
.
from fluent-svelte.
Most components at the moment use the $$restProps feature of svelte, which passes all "unknown" props given to a component down to a specific element as HTML attributes. In fluent-svelte, the element these props are passed down to varies based on the component's functionality. In most cases, it's the outermost element of the rendered component.
So: in most cases you can actually use the style
attribute to some extent. The problem here is that components are not a single element meant to be styled this way. Components are a complex tree of elements that render into an encapsulated UI pattern.
Rather than using this approach, a better method to style fluent-svelte components would be to use global styling + custom class names. At the moment almost all components have the option to provide a class
prop, which will be applied to the outermost element in the component, meaning we can do something like this:
<script>
import { Button } from "fluent-svelte";
</script>
<Button class="custom-button">Button With Custom Styling</Button>
<style>
:global(.custom-button) {
padding: 20px;
}
</style>
This is better for a few reasons:
- It avoids the specificity hell you get into when using inline styles. The
style
attribute can only be overridden by an inline style below it or the!important
flag. - You can still get scoped styles.
:global
in svelte essentially tells the compiler not to attach a hashed classname to a given piece of CSS, but you can also have something like.container :global(.custom-button) {}
which will preserve a scope of.container.svelte-<hash>
. - In general it avoids the confusion of where
{...$$restProps}
will be applied. Classes in fluent-svelte are always applied to the outermost given element.
from fluent-svelte.
If you have any other questions regarding styling limitations, feel free to ask me and i'd be glad to reopen this issue.
from fluent-svelte.
@Tropix126 Yep, I get your point but I find style attribute to be quite useful sometime. Let's keep it that way and thank for the explanation about component styling.
Do you think it should be added in the docs?
from fluent-svelte.
Related Issues (20)
- Pass the current TextBox value as a slot variable for buttons HOT 1
- NavigationView HOT 4
- Adding required dependencies `sass` and `node-sass` in the README / Getting started HOT 4
- Add `color` property to ProgressRing HOT 3
- `<ComboBox>` fires `select` event every time an object in `items` is changed HOT 1
- Draggable ToggleSwitch HOT 1
- Include "Selawik" Font as a font-family fallback
- AutoSuggestBox - Various Details
- Add placement to Combobox flyout
- Add a way to force dark theme HOT 1
- [Question] Up-left menu bar orientation ?
- Fluent Svelte for SvelteKit does not work at all HOT 2
- Expanders inside Expander don't toggle
- RadioButton center part size is bigger than main design
- Is this project still active? HOT 7
- Slider thumb misaligned with ticks
- on:close event of InfoBar won't trigger
- TabList component HOT 1
- Fluent UI v9 Table component missing
- missing exports condition
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluent-svelte.