Code Monkey home page Code Monkey logo

callout-alert's Introduction

callout-alert

A Github / Obsidian inspired web component for displaying a callout in your page.

Several colored banners, each with an icon, title, and text.

Live Example on Codepen

How to use

<script src="https://unpkg.com/callout-alert@1"></script>

<callout-alert type="tip">
  Optional information to help a user be more successful.
</callout-alert>

Types of Alerts

The following types are available by default:

type color icon title
note blue info circle Note
tip green lightbulb Tip
important purple report comment Important
warning yellow warning triangle Warning
caution red report octogon Caution
Default grey document icon Note

You can also configure the Color, Icon, and Title using CSS variables or slots.

CSS API

The following CSS variables can be used to control the presentation of the component:

--callout-color
Used to set the color of the component. Currently must be a set of 3 numbers, the red, green, and blue value.
--callout-icon
Icon to use, you can use any value from Google's Icon Font.
--callout-title
Title for the callout. Can be any string.

You can set some or all of these for a specific callout-alert instance, or at a page level.

<style>
  callout-alert {
    --callout-color: 0, 200, 225;
    --callout-icon: 'bolt';
    --callout-title: 'Alert';
  }
</style>

<callout-alert> Watch out for Lightning bolts! </callout-alert>

Slot API

You can use the following slot names to change the icon or title of the callout.

icon
Can be used to override the icon.
title
Can be used to override the title.

You can set some or all of these inside a callout-alert instance.

<callout-alert type="tip">
  <span slot="icon">๐Ÿ“ฆ</span>
  <span slot="title">Slots</span>
  This is a custom alert, that uses slots to set the icon and title.
</callout-alert>

Known Limitations

Below are a list of known limitations. While there may be available solutions here, an effort has been made to make the code as straight-forward as possible.

Colors

Until relative CSS colors are universally supported, the colors are defined as three numbers. Ideally, once relative colors are supported, we would allow any CSS color (this will be marked as a breaking change, if introduced).

Icon Library

By default, this component loads Google's Material Icon font in the owner document using javascript. Sadly, it's currently not possible to load font-families from a web component context, or from a stylesheet in a component.

Development

This component was built using Tram-Lite, you can read more about the project at https://tram-one.io/tram-lite/.

You can load all the component variants, plus a slot and CSS variable example by running:

npm ci
npm run build
npm start

Then, navigate to the listed IP address /example.

callout-alert's People

Contributors

jrjurman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

callout-alert's Issues

Allow external styling with CSS Parts

Shoelace and other libraries use the ::part() syntax to allow external styling, so we should look into that as well!

This would not be a replacement for the existing CSS variables, but would allow consumers to tweak more underlying styles in these elements.

Head's up: A shortcoming of using strings as the `title`

This looks neat!

I thought you should know, the title has one major shortcoming: it can't use HTML.
Some titles in a typical alert / notification / callout might have inline elements, e.g. emphasis, bold, time elements, etc.

Other than that, great use of a Web Component :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.