Closed Dudek-AMS closed 1 year ago
Thank you for your contribution.
Currently, we don't have a plan to move styles globally.
But you can set color
props to none
and add your classes using class="your-class"
.
While this work, it will force me to do this every time i use the component adding redudant code and bad dx... ofc i could make a wrapper and then use the flowbite component inside with the correct classes - but still think its bad design
Can you add your class to the tailwind.config.cjs
and use it in your components?
Or you can try one of Headless UIs?
Its the component from flowbite-svelte itsself which makes it impossible to use 'custom' themes.... i can set color to none and then define all the classes I want to have - works but i will to do this every time im going to use the component
But I can't define presets for the components
<Button color="primary">abc</Button>
is a preset you defined in the components...... but I wont be able to use
<Button color="myCustomColor"></Button>
Thats why i suggest to outsource the color presets out of the component and make them accessible via config file or better via a global export/svelte story
By doing that I assume there will be many items in the config file and styling will be done in the the file rather than your svelte file. I'm now sure if other uses want to do in that way.
Well you will only need the config files if you have the need for it. Otherwise use default values
Going svelte store way people can easily split the code and add the things they want to do in runtime If making config files its still possible to import differenct config files and use a (deep)merge. So you can still split code like you want.
Do you want to show some examples forking this stackblitz?
"$lib/flowbite.theme.js"; and "$lib/NewButton.svelte" shall not be part of the userland code, but from the flowbite-svelte library
modified theme in +layout.svelte, but could be done anywhere else - even outside of svelte.
This is in line with my approach presented in #711. I'll spend some time on it during the weekend to move it forward.
I can see the benefit of doing this way but there are disadvantage:
<script>
import { ButtonGroup, Button, Label } from 'flowbite-svelte';
import NewButton from "$lib/NewButton.svelte";
import { theme } from '$lib/flowbite.theme.js';
if (!$theme.buttons.colorClasses.light.includes('text-red-900')) {
$theme.buttons.colorClasses.light = '!text-red-900 ' + $theme.buttons.colorClasses.light;
}
</script>
<div class='p-16'>
<div class="py-4">Pills</div>
<ButtonGroup class="space-x-px">
<Button color="light" class="!text-red-900">Profile</Button>
<Button color="light" class="!text-green-900">Settings</Button>
<Button color="light" class="!text-purple-500">Messages</Button>
</ButtonGroup>
<div class="py-4">Pills NewButton but extended</div>
<ButtonGroup class="space-x-px">
<NewButton color="light">Profile</NewButton>
<NewButton color="light">Settings</NewButton>
<NewButton color="light">Messages</NewButton>
</ButtonGroup>
</div>
Benefit: Users can change their style by overwriting Svelte store values.
Disadvantage: Not flexible as you see in the above example when you want to change the color by button. You have to use unnecessary if-statements if you want to change different values.
I'm also pulling out my hair trying to overcome hardcoded classes. Especially on the Input element where it seems that you cannot override the classes at all, you can just append or prepend additional classes, leading to a lot of duplication of classes on the element ...unless I'm missing something.
@ron-wade There is a PR for your issue that we may merge. But not at the moment.
Well you would change the theme store somewhere else, not where you gonna use the components - like a global layout file or even complety outside of svelte - but i see your point and i think there's a solution...
the simple appending is a really bad example - i see two solutions for it
1) use a custom store, checking the classes and filter out duplicates before updating the store 2) use a helper function in userland
import { theme, deduplicateCSSClasses } from '$lib/flowbite.theme.js';
$theme.buttons.colorClasses.light = deduplicateCSSClasses($theme.buttons.colorClasses.light + ' text-red-900');
function deduplicateCSSClasses(input: string) : string {
let splitted = input.split(/\s+/);
let uniqued = [...new Set(splitted)];
return uniqued.join(' ');
}
Not flexible as you see in the above example when you want to change the color by button.
If you need to change the color per button (one time usage) - the suggested change isnt what its for... its just if you want to re-use it on multiple times, probably all over your project.
v0.38.1 uses Tailwind Merge so that you can overwrite styles by adding them to the class. Please try it out and let us know what you think.
<script>
import { Button } from 'flowbite-svelte'
</script>
<Button href="/about" class="!bg-blue-500">
Button 1
</Button>
<Button href="/about" class="!bg-green-500">
Button 2
</Button>
I too am unable to get this to work. I'm using the exclamation point before the classes, nothing is working.
It keeps choosing the default class no matter on the NavUl. For some reason, the tailwind merge isn't working for it. The padding color is always bg-gray-800.
v0.38.1 uses Tailwind Merge so that you can overwrite styles by adding them to the class. Please try it out and let us know what you think.
<script> import { Button } from 'flowbite-svelte' </script> <Button href="/about" class="!bg-blue-500"> Button 1 </Button> <Button href="/about" class="!bg-green-500"> Button 2 </Button>
thats not the same like suggested example.. i will need to reduplicate all the code everytime im gonna use it.
@Dudek-AMS You can take this approach.
// src/lib/MyButton.svelte
<script>
import { Button } from 'flowbite-svelte'
</script>
<Button color="green" pill class="p-8">
<slot />
</Button>
<script>
import MyButton from "$lib/MyButton.svelte"
</script>
<MyButton>My New Button</MyButton>
https://sveltejskittemplatedefaultefqg-kxp3--5173--77657b1e.local-corp.webcontainer.io/customization
I close the issue for now. Thank you for your contribution. Please feel free to open a new issue.
Im using the Button Component with a custom primary color and a 'href' attribute
inside my global.css i set colors for links
the link inside the button will be text-primary-600 on hover while the button is bg-primary-800 and i have to explicitely use hover:text-white on the Button element to prevent it being unreadable.
Solution: checking the code of the component
instead of hardcoding it i suggest using a global store or some other method, to allow modyfing it during runtime like
doing this way would also allow to add new colors to the components