tailwind
tailwind copied to clipboard
question on dependancies... and older theme
Added npm install --save @nativescript/tailwind tailwindcss
removed .. "@nativescript/theme": "~3.1.0", "nativescript-theme-core": "~1.0.4", Are these required ?
For using tailwind no they are not.
Perfect. Thanks. Looking to implement a theme switcher. The sample has a config of darkMode: ['class', '.ns-dark'],
So switching theme light/dark. On main application Gridlayout would I apply class=ns-dark, or ns-light? Any thoughts on approach to theme switching?
tailwindcss rocks ;)
cheers, Aj
I've made a quick util for this, see https://x.com/igor_randj/status/1834615699974529313
import { Application, CSSUtils } from '@nativescript/core';
export function toggleGlobalClass(className: string) {
const rootView = Application.getRootView();
const enabled = rootView.cssClasses.has(className);
if (enabled) {
CSSUtils.removeSystemCssClass(className);
rootView.cssClasses.delete(className);
// also remove from all modals
rootView._getRootModalViews().forEach((view) => {
view.cssClasses.delete(className);
view._onCssStateChange();
});
} else {
CSSUtils.pushToSystemCssClasses(className);
rootView.cssClasses.add(className);
// also add to all modals
rootView._getRootModalViews().forEach((view) => {
view.cssClasses.add(className);
view._onCssStateChange();
});
}
rootView._onCssStateChange();
}