Giter Club home page Giter Club logo

grille-pain's Introduction

🍞 Grille-Pain — The French Toaster

grille_pain is a toaster for lustre, and gleam in a more general manner. It tries to be both simple to use, and simple to customise to adapt to your use case. Features could be missing, as grille_pain is also an experimentation to add support for effect managers for lustre. It can however completely be used in your application, even if you're not using lustre. grille_pain will never breaks intentionnally, and will always take care of providing non-breaking minor updates, but you can potentially expect lot of major updates while design of effect managers evolve!

Because a demo is worth thousand words, you can find one directly here.

In order to work without disturbing your application, grille_pain behaves as an independant component on the page. After setup, grille_pain registers a <grille_pain> node in the DOM, and instanciate a Shadow DOM, to make sure styles won't intervene with yours.

This package is inspired by react-toastify, for colors and animations.

Warning

It's only working for JavaScript target as of now!

Installation

gleam add grille_pain

Quickstart

import gleam/pair
import grille_pain
import grille_pain/lustre/toast
import grille_pain/toast/level
import lustre
import lustre/attribute
import lustre/effect
import lustre/element/html
import lustre/event
import sketch/lustre as sketch_lustre
import sketch/options as sketch_options

pub type Model =
  Int

pub type Msg {
  DisplayBasicToast(content: String)
}


pub fn main() {
  let assert Ok(_) = grille_pain.simple()
  let assert Ok(_) =
    lustre.application(init, update, view)
    |> lustre.start("#app", Nil)
}

fn init(_flags) {
  #(0, effect.none())
}

fn update(model: Model, msg: Msg) {
  case msg {
    DisplayBasicToast(content) ->
      #(model, toast.toast(content))
  }
}

fn view(model: Model) {
  html.div([], [
    html.button([event.on_click(DisplayBasicToast("Success"))], [
      html.text("Display toast")
    ])
  ])
}

Usage

Setup of grille_pain is achieved using grille_pain.simple() or grille_pain.setup() and passing diverse options, like the default timeout for toasts. Once setup, if you're using lustre, you should only take care of grille_pain/lustre/toast and use them in your update function, while if not using lustre, you can use grille_pain/toast. But be careful, this module is side-effectful.

Displaying a toast is as simple as toast.toast("Content"), or you can build your custom toast. The documentation is hosted on hex.

Styling

Toasts are styled by default, except for fonts. To define a font that suits you, you have to define a font on the html, body or grille-pain node in the DOM. Fonts will pierce in the Shadow DOM and apply to the toasts!

If the default appearance of toasts does not please you, you can always style the toasts! To do it, you have multiple CSS variables, that you can set on the grille-pain node, directly in CSS.

Here, the different options, with their default values.

grille-pain {
  /* Common options for toasts */
  --grille_pain-width: 320px;                       /* Wrapper size*/
  --grille_pain-toast-width: 320px;                 /* Toast size */
  --grille_pain-toast-min-height: 64px;             /* Toast min height */
  --grille_pain-toast-max-height: 800px;1           /* Toast max height */
  --grille_pain-toast-border-radius: 6px;           /* Toast border radius */

  /* Color for standard toast */
  --grille_pain-Standard-background: #ffffff;       /* Background color */
  --grille_pain-Standard-text-color: #121212;       /* Text color */
  --grille_pain-Standard-progress-bar: #000000b3;   /* Progress bar color */

  /* Color for info toast */
  --grille_pain-Info-background: #3498db;           /* Background color */
  --grille_pain-Info-text-color: #ffffff;           /* Text color */
  --grille_pain-Info-progress-bar: #ffffffb3;       /* Progress bar color */

  /* Color for warning toast */
  --grille_pain-Warning-background: #f1c40f;       /* Background color */
  --grille_pain-Warning-text-color: #ffffff;       /* Text color */
  --grille_pain-Warning-progress-bar: #ffffffb3;   /* Progress bar color */

  /* Color for error toast */
  --grille_pain-Error-background: #e74c3c;         /* Background color */
  --grille_pain-Error-text-color: #ffffff;         /* Text color */
  --grille_pain-Error-progress-bar: #ffffffb3;     /* Progress bar color */

  /* Color for success toast */
  --grille_pain-Success-background: #07bc0c;       /* Background color */
  --grille_pain-Success-text-color: #ffffff;       /* Text color */
  --grille_pain-Success-progress-bar: #ffffffb3;   /* Progress bar color */
}

Contributing

You love the package and want to improve it? You have a shiny new framework and want to provide an integration with grille_pain in this package? Every contribution is welcome! Feel free to open a Pull Request, and let's discuss about it!

grille-pain's People

Contributors

ghivert avatar

Stargazers

Lulzx avatar Rafał Chomczyk avatar  avatar  avatar Andrew Chou avatar Andy Jones avatar Zoo Sky avatar Comamoca avatar Giovanni Kock Bonetti avatar Edgars Burtnieks avatar Isaac avatar Michał Łępicki avatar

Watchers

 avatar

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.