@themillhousegroup/svelte-common-ui
v0.0.12
Published
Common user-interface controls for Svelte (v5) webapps
Downloads
25
Maintainers
Readme
svelte-common-ui
Simple components for common styling tasks in a Svelte (5) app.
Warning
This library is currently under development and is not yet ready for production use.
Guiding principles
- No "legacy" (pre-v5) Svelte
- Strong types
- Good starting points, but easy to extend if needed
Components
ThemeProvider
Example
https://themillhousegroup.github.io/svelte-common-ui/
Usage
<ThemeProvider {allThemes} themeName={themeName} >
<h4>This child has been themed</h4>
</ThemeProvider>Setup
ThemeProvider makes heavy use of types to ensure that:
- the
themeNamebelongs toallThemes - each
ThemewithinallThemescontains all the required CSS variables - each CSS variable is in the form
--theme-${string}
Check the routes/+page.svelte file for an example that sets up 3 theme names and adds custom theme variables.
Defaults
Out of the box, you can get started straight away with the default ThemeNames LIGHT and DARK.
You will also need to set up some colors to satisfy the requirements of the CorePropertyNameList:
--theme-background-color--theme-matte-color--theme-border-color--theme-color
So for example:
import { ThemeName, Theme, AllThemePropertyNames } from 'svelte-common-ui';
const allThemes: Record<ThemeName, Theme<AllThemePropertyNames> = {
LIGHT: {
"--theme-background-color": "white",
"--theme-matte-color": "#d0d0f0b0",
"--theme-border-color": "#bbf",
"--theme-color": "blue",
},
DARK: {
"--theme-background-color": "black",
"--theme-matte-color": "#202020b0",
"--theme-border-color": "#005",
"--theme-color": "gray",
},
};Now you can use the ThemeProvider as per the "Usage" section above.
Demo page setup
Follows the SvelteKit Guide using the adapter-static.
Development details
From this point in the README onwards are details generated by the sv create tool that built this library target.
Svelte library
Everything you need to build a Svelte library, powered by sv.
Read more about creating a library in the docs.
Creating a project
If you're seeing this, you've probably already done this step. Congrats!
# create a new project in the current directory
npx sv create
# create a new project in my-app
npx sv create my-appDeveloping
Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --openEverything inside src/lib is part of your library, everything inside src/routes can be used as a showcase or preview app.
Building
To build your library:
npm run packageTo create a production version of your showcase app:
npm run buildYou can preview the production build with npm run preview.
To deploy your app, you may need to install an adapter for your target environment.
Publishing
Go into the package.json and give your package the desired name through the "name" option. Also consider adding a "license" field and point it to a LICENSE file which you can create from a template (one popular option is the MIT license).
To publish your library to npm:
npm publish --provenance --access public