Package Exports
- svelte-weather
- svelte-weather/Alien.svelte
- svelte-weather/Barometer.svelte
- svelte-weather/Celsius.svelte
- svelte-weather/Cloud.svelte
- svelte-weather/CloudDown.svelte
- svelte-weather/CloudRefresh.svelte
- svelte-weather/CloudUp.svelte
- svelte-weather/Cloudy.svelte
- svelte-weather/CloudyGusts.svelte
- svelte-weather/CloudyWindy.svelte
- svelte-weather/DayCloudy.svelte
- svelte-weather/DayCloudyGusts.svelte
- svelte-weather/DayCloudyHigh.svelte
- svelte-weather/DayCloudyWindy.svelte
- svelte-weather/DayFog.svelte
- svelte-weather/DayHail.svelte
- svelte-weather/DayHaze.svelte
- svelte-weather/DayLightWind.svelte
- svelte-weather/DayLightning.svelte
- svelte-weather/DayRain.svelte
- svelte-weather/DayRainMix.svelte
- svelte-weather/DayRainWind.svelte
- svelte-weather/DayShowers.svelte
- svelte-weather/DaySleet.svelte
- svelte-weather/DaySleetStorm.svelte
- svelte-weather/DaySnow.svelte
- svelte-weather/DaySnowThunderstorm.svelte
- svelte-weather/DaySnowWind.svelte
- svelte-weather/DaySprinkle.svelte
- svelte-weather/DayStormShowers.svelte
- svelte-weather/DaySunny.svelte
- svelte-weather/DaySunnyOvercast.svelte
- svelte-weather/DayThunderstorm.svelte
- svelte-weather/DayWindy.svelte
- svelte-weather/Degrees.svelte
- svelte-weather/DirectionDown.svelte
- svelte-weather/DirectionDownLeft.svelte
- svelte-weather/DirectionDownRight.svelte
- svelte-weather/DirectionLeft.svelte
- svelte-weather/DirectionRight.svelte
- svelte-weather/DirectionUp.svelte
- svelte-weather/DirectionUpLeft.svelte
- svelte-weather/DirectionUpRight.svelte
- svelte-weather/Dust.svelte
- svelte-weather/Earthquake.svelte
- svelte-weather/Fahrenheit.svelte
- svelte-weather/Fire.svelte
- svelte-weather/Flood.svelte
- svelte-weather/Fog.svelte
- svelte-weather/GaleWarning.svelte
- svelte-weather/Hail.svelte
- svelte-weather/Horizon.svelte
- svelte-weather/HorizonAlt.svelte
- svelte-weather/Hot.svelte
- svelte-weather/Humidity.svelte
- svelte-weather/Hurricane.svelte
- svelte-weather/HurricaneWarning.svelte
- svelte-weather/Icon.svelte
- svelte-weather/Lightning.svelte
- svelte-weather/LunarEclipse.svelte
- svelte-weather/Meteor.svelte
- svelte-weather/MoonAltFirstQuarter.svelte
- svelte-weather/MoonAltFull.svelte
- svelte-weather/MoonAltNew.svelte
- svelte-weather/MoonAltThirdQuarter.svelte
- svelte-weather/MoonAltWaningCrescent1.svelte
- svelte-weather/MoonAltWaningCrescent2.svelte
- svelte-weather/MoonAltWaningCrescent3.svelte
- svelte-weather/MoonAltWaningCrescent4.svelte
- svelte-weather/MoonAltWaningCrescent5.svelte
- svelte-weather/MoonAltWaningCrescent6.svelte
- svelte-weather/MoonAltWaningGibbous1.svelte
- svelte-weather/MoonAltWaningGibbous2.svelte
- svelte-weather/MoonAltWaningGibbous3.svelte
- svelte-weather/MoonAltWaningGibbous4.svelte
- svelte-weather/MoonAltWaningGibbous5.svelte
- svelte-weather/MoonAltWaningGibbous6.svelte
- svelte-weather/MoonAltWaxingCrescent1.svelte
- svelte-weather/MoonAltWaxingCrescent2.svelte
- svelte-weather/MoonAltWaxingCrescent3.svelte
- svelte-weather/MoonAltWaxingCrescent4.svelte
- svelte-weather/MoonAltWaxingCrescent5.svelte
- svelte-weather/MoonAltWaxingCrescent6.svelte
- svelte-weather/MoonAltWaxingGibbous1.svelte
- svelte-weather/MoonAltWaxingGibbous2.svelte
- svelte-weather/MoonAltWaxingGibbous3.svelte
- svelte-weather/MoonAltWaxingGibbous4.svelte
- svelte-weather/MoonAltWaxingGibbous5.svelte
- svelte-weather/MoonAltWaxingGibbous6.svelte
- svelte-weather/MoonFirstQuarter.svelte
- svelte-weather/MoonFull.svelte
- svelte-weather/MoonNew.svelte
- svelte-weather/MoonThirdQuarter.svelte
- svelte-weather/MoonWaningCrescent1.svelte
- svelte-weather/MoonWaningCrescent2.svelte
- svelte-weather/MoonWaningCrescent3.svelte
- svelte-weather/MoonWaningCrescent4.svelte
- svelte-weather/MoonWaningCrescent5.svelte
- svelte-weather/MoonWaningCrescent6.svelte
- svelte-weather/MoonWaningGibbous1.svelte
- svelte-weather/MoonWaningGibbous2.svelte
- svelte-weather/MoonWaningGibbous3.svelte
- svelte-weather/MoonWaningGibbous4.svelte
- svelte-weather/MoonWaningGibbous5.svelte
- svelte-weather/MoonWaningGibbous6.svelte
- svelte-weather/MoonWaxing6.svelte
- svelte-weather/MoonWaxingCrescent1.svelte
- svelte-weather/MoonWaxingCrescent2.svelte
- svelte-weather/MoonWaxingCrescent3.svelte
- svelte-weather/MoonWaxingCrescent4.svelte
- svelte-weather/MoonWaxingCrescent5.svelte
- svelte-weather/MoonWaxingGibbous1.svelte
- svelte-weather/MoonWaxingGibbous2.svelte
- svelte-weather/MoonWaxingGibbous3.svelte
- svelte-weather/MoonWaxingGibbous4.svelte
- svelte-weather/MoonWaxingGibbous5.svelte
- svelte-weather/MoonWaxingGibbous6.svelte
- svelte-weather/Moonrise.svelte
- svelte-weather/Moonset.svelte
- svelte-weather/Na.svelte
- svelte-weather/NightAltCloudy.svelte
- svelte-weather/NightAltCloudyGusts.svelte
- svelte-weather/NightAltCloudyHigh.svelte
- svelte-weather/NightAltCloudyWindy.svelte
- svelte-weather/NightAltHail.svelte
- svelte-weather/NightAltLightning.svelte
- svelte-weather/NightAltPartlyCloudy.svelte
- svelte-weather/NightAltRain.svelte
- svelte-weather/NightAltRainMix.svelte
- svelte-weather/NightAltRainWind.svelte
- svelte-weather/NightAltShowers.svelte
- svelte-weather/NightAltSleet.svelte
- svelte-weather/NightAltSleetStorm.svelte
- svelte-weather/NightAltSnow.svelte
- svelte-weather/NightAltSnowThunderstorm.svelte
- svelte-weather/NightAltSnowWind.svelte
- svelte-weather/NightAltSprinkle.svelte
- svelte-weather/NightAltStormShowers.svelte
- svelte-weather/NightAltThunderstorm.svelte
- svelte-weather/NightClear.svelte
- svelte-weather/NightCloudy.svelte
- svelte-weather/NightCloudyGusts.svelte
- svelte-weather/NightCloudyHigh.svelte
- svelte-weather/NightCloudyWindy.svelte
- svelte-weather/NightFog.svelte
- svelte-weather/NightHail.svelte
- svelte-weather/NightLightning.svelte
- svelte-weather/NightPartlyCloudy.svelte
- svelte-weather/NightRain.svelte
- svelte-weather/NightRainMix.svelte
- svelte-weather/NightRainWind.svelte
- svelte-weather/NightShowers.svelte
- svelte-weather/NightSleet.svelte
- svelte-weather/NightSleetStorm.svelte
- svelte-weather/NightSnow.svelte
- svelte-weather/NightSnowThunderstorm.svelte
- svelte-weather/NightSnowWind.svelte
- svelte-weather/NightSprinkle.svelte
- svelte-weather/NightStormShowers.svelte
- svelte-weather/NightThunderstorm.svelte
- svelte-weather/Rain.svelte
- svelte-weather/RainMix.svelte
- svelte-weather/RainWind.svelte
- svelte-weather/Raindrop.svelte
- svelte-weather/Raindrops.svelte
- svelte-weather/Refresh.svelte
- svelte-weather/RefreshAlt.svelte
- svelte-weather/Sandstorm.svelte
- svelte-weather/Showers.svelte
- svelte-weather/Sleet.svelte
- svelte-weather/SmallCraftAdvisory.svelte
- svelte-weather/Smog.svelte
- svelte-weather/Smoke.svelte
- svelte-weather/Snow.svelte
- svelte-weather/SnowWind.svelte
- svelte-weather/SnowflakeCold.svelte
- svelte-weather/SolarEclipse.svelte
- svelte-weather/Sprinkle.svelte
- svelte-weather/Stars.svelte
- svelte-weather/StormShowers.svelte
- svelte-weather/StormWarning.svelte
- svelte-weather/StrongWind.svelte
- svelte-weather/Sunrise.svelte
- svelte-weather/Sunset.svelte
- svelte-weather/Thermometer.svelte
- svelte-weather/ThermometerExterior.svelte
- svelte-weather/ThermometerInternal.svelte
- svelte-weather/Thunderstorm.svelte
- svelte-weather/Time1.svelte
- svelte-weather/Time10.svelte
- svelte-weather/Time11.svelte
- svelte-weather/Time12.svelte
- svelte-weather/Time2.svelte
- svelte-weather/Time3.svelte
- svelte-weather/Time4.svelte
- svelte-weather/Time5.svelte
- svelte-weather/Time6.svelte
- svelte-weather/Time7.svelte
- svelte-weather/Time8.svelte
- svelte-weather/Time9.svelte
- svelte-weather/Tornado.svelte
- svelte-weather/Train.svelte
- svelte-weather/Tsunami.svelte
- svelte-weather/Umbrella.svelte
- svelte-weather/Volcano.svelte
- svelte-weather/WindBeaufort0.svelte
- svelte-weather/WindBeaufort1.svelte
- svelte-weather/WindBeaufort10.svelte
- svelte-weather/WindBeaufort11.svelte
- svelte-weather/WindBeaufort12.svelte
- svelte-weather/WindBeaufort2.svelte
- svelte-weather/WindBeaufort3.svelte
- svelte-weather/WindBeaufort4.svelte
- svelte-weather/WindBeaufort5.svelte
- svelte-weather/WindBeaufort6.svelte
- svelte-weather/WindBeaufort7.svelte
- svelte-weather/WindBeaufort8.svelte
- svelte-weather/WindBeaufort9.svelte
- svelte-weather/WindDeg.svelte
- svelte-weather/Windy.svelte
Readme
Svelte Weather
210+ SVG weather icons for Svelte.
Thank you for considering my open-source package. If you use it in a commercial project, please support me by sponsoring me on GitHub: https://github.com/sponsors/shinokada. Your support helps me maintain and improve this package for the benefit of the community.
Repo
Original source
erikflowers/weather-icons GitHub Repo
License
erikflowers/weather-icons LICENSE
Installation
pnpm i svelte-weatherUsage
<script>import {DayCloudy} from "svelte-weather";</script>Faster compiling
If you need only a few icons from this library in your Svelte app, import them directly. This can optimize compilation speed and improve performance by reducing the amount of code processed during compilation.
<script>
import DayCloudy from 'svelte-weather/DayCloudy.svelte';
</script>
<DayCloudy />Props
- size = ctx.size || '24';
- role = ctx.role || 'img';
- color = ctx.color || 'currentColor';
- ariaLabel = 'file name';
IDE support
If you are using an LSP-compatible editor, such as VSCode, Atom, Sublime Text, or Neovim, hovering over a component name will display a documentation link, features, props, events, and an example.
Size
Use the size prop to change the size of icons.
<DayCloudy size="30" />
<DayCloudy size="40" />
<DayCloudy size="50" />If you are using Tailwind CSS, you can add a custom size using Tailwind CSS by including the desired classes in the class prop. For example:
<DayCloudy class="shrink-0 h-20 w-20" />Setting Global Icon using setContext
You can establish global icon preferences in your Svelte application using setContext. This allows you to configure icon-related properties once and share them across multiple components. Here's how you can do it:
<script>
import { setContext } from 'svelte';
// Define your global icon settings
const iconCtx = {
size: '100', // Icon size in pixels
color: '#ff4488' // Icon color in hexadecimal or CSS color name
};
setContext('iconCtx', iconCtx);
</script>The size, color, and role properties are optional, allowing you to fine-tune the appearance and accessibility of your icons as needed.
If you set size, icons can be customized with different colors. For example:
<script>
import { setContext } from 'svelte';
import { DayCloudy } from 'svelte-weather';
const iconCtx = {
size: '50'
};
setContext('iconCtx', iconCtx);
</script>
<DayCloudy color="#ff4488" />Remember that you can set only one or two of these properties, allowing you to tailor icon settings to your specific design and accessibility requirements.
Feel free to mix and match these properties as needed to create visually appealing and accessible icons in your Svelte application.
Creating a Default Icon Setting
You can create a config file, /src/lib/icon.config.json.
The Icon component serves as a wrapper for svelte:component, allowing you to establish a global default setting or expand the capabilities of a component.
To create a default global icon setting, follow these steps:
Configuration File
Start by creating a configuration file named /src/lib/icon.config.json with the following structure:
{
"config1": {
"size": 40,
"color": "#FF5733"
},
"config2": {
"size": 50,
"color": "#445533"
}
}In this JSON file, you can define different configurations (config1 and config2 in this case) for your icons, specifying attributes like size, variation, and color.
Implementation
In your Svelte page file, make use of the configurations from the JSON file:
<script lang="ts">
type IconConfig = {
config1: {
size: number;
color: string;
};
config2: {
size: number;
color: string;
};
};
import config from '$lib/icon.config.json';
import { Icon, DayLightWind, DaySunny } from 'svelte-weather';
const iconConfig: IconConfig = config;
const config1 = iconConfig.config1;
const config2 = iconConfig.config2;
</script>
<Icon {...config1} icon="{DayLightWind}" />
<Icon {...config2} icon="{DaySunny}" />We import the configurations from the JSON file and assign them to config1 and config2. We then utilize the Icon component with the spread attributes {...config1} and {...config2} to apply the respective configurations to each icon.
Custom Default Icon
If you wish to create a custom default icon, you can follow these steps:
Create a Svelte component named src/lib/MyIcon.svelte:
<script lang="ts">
import type { ComponentType } from 'svelte';
const config = {
size: 30,
color: '#FF5733'
};
import { Icon } from 'svelte-weather';
export let icon: ComponentType;
</script>
<Icon {...config} {icon} />This component, MyIcon.svelte, accepts an icon prop which you can use to pass in the specific icon component you want to display. The default configuration is also applied to the icon.
Implementation in a Page
To use your custom default icon in a Svelte page, do the following:
<script>
import MyIcon from '$lib/MyIcon.svelte';
import { DayLightWind } from 'svelte-weather';
</script>
<MyIcon icon="{DayLightWind}" />Here, we import the MyIcon component and the DayLightWind icon. By passing the DayLightWind icon to the icon prop of MyIcon, you apply the default configuration to the icon.
CSS HEX Colors
Use the color prop to change colors with HEX color code.
<DayCloudy color="#ff0000" /> <DayCloudy color="#00ffd8" />CSS framework support
You can apply CSS framework color and other attributes directly to the icon component or its parent tag using the class prop.
For example, Tailwind CSS:
<DayCloudy class="text-pink-700 mr-4" />Bootstrap example:
<DayCloudy class="position-absolute top-0 px-1" />Dark mode
If you use the dark mode on your website with Tailwind CSS, add your dark mode class to the class prop.
Let's use dark for the dark mode class as an example.
<DayCloudy class="text-pink-700 dark:text-blue-300" />aria-label
All icons have aria-label. For example DayCloudy has aria-label="day cloudy".
Use ariaLabel prop to modify the aria-label value.
<DayCloudy ariaLabel="day cloudy icon" class="text-red-500" />Unfocusable icon
If you want to make an icon unfocusable, add tabindex="-1".
<DayCloudy tabindex="-1" />Events
All icons have the following events:
- on:click
- on:keydown
- on:keyup
- on:focus
- on:blur
- on:mouseenter
- on:mouseleave
- on:mouseover
- on:mouseout
Passing down other attributes
You can pass other attibutes as well.
<DayCloudy tabindex="0" />Using svelte:component
<script>
import { DayCloudy } from 'svelte-weather';
</script>
<svelte:component this="{DayCloudy}" />Using onMount
<script>
import { DayCloudy } from 'svelte-weather';
import { onMount } from 'svelte';
const props = {
size: '50',
color: '#ff0000'
};
onMount(() => {
const icon = new DayCloudy({ target: document.body, props });
});
</script>Import all
Use import * as Icon from 'svelte-weather.
<script>
import * as Icon from 'svelte-weather';
</script>
<Icon.DayCloudy size="30" class="text-red-500" />
<Icon.DirectionRight size="40" class="text-blue-700" />
<Icon.Hail size="50" class="text-green-700" />
<Icon.MoonAltWaningGibbous2 size="60" class="text-purple-500" />
<Icon.NightAltSleet size="100" class="text-purple-500" tabindex="0" />