# Blue Web Blue Web is the base library for [Blue React](https://bruegmann.github.io/blue-react) and [Blue Blazor](https://bruegmann.github.io/blue-react). This library builds heavily on top of [Bootstrap](https://getbootstrap.com/docs/) and also provides additional solutions in CSS and JavaScript. ## Use Blue Web Install with NPM: ``` npm i blue-web ``` [![npm version](https://img.shields.io/npm/v/blue-web)](https://www.npmjs.com/package/blue-web) ## Implementation If you have a React or Blazor project, you should use the components of [Blue React](https://bruegmann.github.io/blue-react) or [Blue Blazor](https://bruegmann.github.io/blue-blazor). Otherwise you can also write the markup of those components directly in HTML. Check out the examples in the docs to find out how. For the JavaScript solutions you have to import the associated file. When installed using NPM, you can do it like this: ```js import "blue-web/dist/js/dialog.js" import "blue-web/dist/js/progress.js" // ... ``` **Important:** Since 1.14.0 JavaScript files are compiled as ES modules. When you embed them in HTML using the ` ``` JavaScript files are compiled as ES modules. This allows you to use import functions like this: ```html ``` ## Customization and theming Since Blue Web is based on Bootstrap, you can customize many things by overriding Sass or CSS variables. For more information, see the [Bootstrap documentation](https://getbootstrap.com/docs/5.3/customize/overview/). Blue Web also provides some additional variables that you can use and override. Take a look at [dist/styles/\_variables.scss](https://github.com/bruegmann/blue-web/blob/main/dist/styles/_variables.scss) to see all of them. Here is an example of how to override variables using Sass: ```scss // Override Bootstrap Sass variable $primary: tomato; // Override Blue Web Sass variables $theme: orange; $theme-dark: darken(orange, 10%); // Stylesheet for Blue Web. Already contains Bootstrap. @import "~blue-web/dist/style"; ``` An example of how to override CSS variables: ```css :root { /* Override Bootstrap CSS variable */ --bs-body-font-family: "Inter", sans-serif; /* Override Blue Web CSS variable */ --blue-sidebar-bg: #333; } ``` ## Button with icon Blue Web enhances [Bootstrap's icon link helper](https://getbootstrap.com/docs/5.3/helpers/icon-link/#example) with the `.blue-btn-icon-wrapper` class, enabling icons to be wrapped in a `span` element. This simplifies the integration for Blue React and Blue Blazor by allowing icons to be passed as props more easily. ```html ``` ## Buttons Blue Web added some button variants to Bootstrap's default button styles. These variants are designed to be used in conjunction with the default Bootstrap button classes. ### `.blue-btn-soft-*` ```html ``` ### `.blue-btn-plain-*` A plain variant of Bootstrap's buttons. Always use together with `.btn`! ```html ``` ## Collapse Animated collapse using HTML `details`. ```html
Collapse
Show something
``` Element with class `blue-collapse-chevron` will be rotated to `90deg` by default and if it is the first child. If it's the last child it will rotate to `-90deg`. Since text nodes aren't considered as child elements, you should wrap your text around an element. `Collapse` in this case: ```html
Collapse
Show something
``` You can also customize the rotation target position with the CSS variable `--blue-collapse-chevron-rotate`: ```html
Collapse
Show something
``` ### Combine with styling of Menu Item ```html
Parent
``` ### Menu Item and Collapse grouped `.blue-collapse-group` let's you group a collapse together with another UI element like a button that should come before the collapse summary. ```html
Collapse sub menu
``` ## Container Grid ### `.blue-container-grid` Adds container query support to Bootstrap's grid system. By default, Bootstrap's breakpoint classes only react to changes in the viewport width. With container queries, you can apply breaks based on a custom container. - [Read more about container queries](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries) - [Read more about Bootstrap's grid system](https://getbootstrap.com/docs/5.3/layout/grid/) ```html
col-md-4
col-md-8
``` ```html
col-md-4
col-md-8
This is a container grid. Resize the box around to see the effect.
``` ## Input group Special variant of [input group](https://getbootstrap.com/docs/5.3/forms/input-group). The whole group will have a focus ring when an inner input is focussed. And styling for `.input-group-text` is simplified. ### Search This variant is especially useful for search input. ```html
``` ## Layout Blue Web offers a set of code to create a layout with a header, collapsible sidebar, and a main content area. ```html
Your header here
Your main content here
``` ### Adjust header logo size using CSS variable Implementations for [React](https://bruegmann.github.io/blue-react/v10/component/HeaderTitle) and [Blazor](https://bruegmann.github.io/blue-blazor/components/header-title/props) provide components to set a layout header with a logo and app title. By default the logo size is `2rem`. You can override that value with CSS variable `--blue-header-title-image-size`: ```html
My logo
``` If your logo has another width than height, you can also use a combination of `--blue-header-title-image-width` and `--blue-header-title-image-height`. ## Menu Item Styles for interactive elements in sidebar and in header area. ```html ``` ### Dropdown with Popover API and Anchor Positioning In combination with the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) and [CSS Anchor Positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning) you can create a dropdown menu without the need for custom JavaScript. Blue Web provides some helper CSS classes for anchoring. With `.blue-anchor` you define the anchor, with `.blue-anchored` the target that will be attached to it. With the CSS variable `--blue-anchor-name` you define the shared anchor name. ```html
``` #### Polyfill As of writing this, CSS Anchor Positioning doesn't work in all major browsers yet ([Can I Use](https://caniuse.com/css-anchor-positioning)). You might need a polyfill. You can find one here: [https://github.com/oddbird/css-anchor-positioning](https://github.com/oddbird/css-anchor-positioning). You can quickly apply it like this: ```html ``` #### Fallback Add `.blue-anchored-fallback` to the dropdown element and on not supported browsers, it will be displayed with an overlay over the whole page. #### Position This is how to place the menu right to the button: ```html
``` #### Initially open You can open the dropdown using JavaScript with `showPopover()`. ```html
``` ### Combine with Collapse Together with `.blue-collapse` and [`
`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/details) you can create a collapsable sub menu. Could be used inside the sidebar. [Click here to go the example on the Collapse page](css/Collapse#combine-with-menu-item). ## Modal Allows to use [Bootstrap Modals](https://getbootstrap.com/docs/5.3/components/modal/) but with the native dialog element and without the need of Bootstrap's JavaScript. ```html
``` ### Offcanvas Because [Bootstrap Offcanvas](https://getbootstrap.com/docs/5.3/components/offcanvas/) works quite similar, you can also use `.blue-modal` with that. ```html
Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
``` ### Modal in Offcanvas ```html
Offcanvas
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
``` ## Neumorphism SCSS utilities (Experimental) Blue Web comes with `dist/neu.scss` containing some SCSS and CSS utilities to make it easy to apply shadow effects. The effects can have some weird side-effects, that's why they are not included by default with `dist/style.scss`. You have to embed it yourself. ### Getting started 1. Import neu.css in your main SCSS file: ```scss @import "~blue-react/dist/neu"; ``` 2. Apply the mixin "neu()" at the area you want to use it: ```scss :root { @include neu(#610dfd); } ``` First parameter takes the areas's background color. As second parameter you can set the background color for inset. ### Utility classes The notation looks like this: `.neu-shadow{-inset?}{-switch?}{-size}` - Where `inset` is optional. When you set it, the box-shadow will be set to the inside. - Where `switch` is optional. When you set it, the light and dark shadow colors will be switched. **Can only be used together with `inset`!** - Where size is required and one of: - `1` - distance and blur values multiplied with `.25` - `2` - distance and blur values multiplied with `.5` - `3` - distance and blur values multiplied with `1` - `4` - distance and blur values multiplied with `1.5` - `5` - distance and blur values multiplied with `3` Format and the values are inspired by [Bootstrap](https://getbootstrap.com/docs/5.3/utilities/spacing/#notation). ### Combining classes You can combine shadows with inset shadows like this: ```html
``` ```scss .bg-body { @include neu($body-bg, $body-bg); } @include color-mode(dark) { .bg-body { @include neu($body-bg-dark, $body-bg-dark); } } ``` ### CSS variables You can use Neu's CSS variables and combine them like this:\ `style="var(--neu-shadow-3), var(--neu-shadow-inset-switch-1)"` The notation is similar to the Utility classes. ### Examples You can combine shadows to different soft effects. ```html
Neumorph card
``` ## Scrollbar ### `.blue-scroll-shadow` Adds shadow if area is scrollable. ```html
``` ## Sidebar ### `.blue-sidebar-exception` Prevents the default behaviour of closing sidebar after clicking an item. ### `.blue-sidebar-bottom` With Sidebar Bottom, for example, a registered user can be displayed at the bottom left. Usable within ``. ### `.blue-sidebar-hidden-on-open` The element is hidden as long as the sidebar is open. ### `.blue-sidebar-pseudo-hidden-on-open`, `.blue-sidebar-before-hidden-on-open`, `.blue-sidebar-afters-hidden-on-open` Pseudo elements of element are hidden as long as the sidebar is open. `.blue-sidebar-before-hidden-on-open` hides `::before`,`.blue-sidebar-after-hidden-on-open` hides `::after` and `.blue-sidebar-pseudo-hidden-on-open will` hide both. ### `.blue-sidebar-d-flex-on-open` Alias: `.blue-sidebar-visible-on-open` The element is visible (`display: flex`) as long as the sidebar is open. ### `.blue-sidebar-d-block-on-open` The element is visible (`display: block`) as long as the sidebar is open. ### `.w-bla-sidebar-width` Gives element the width of the sidebar, defined with `$bla-sidebar-width`. ### `.blue-sidebar-state`(`.open`) Use this to control the state of the sidebar and sidebar menu items inside. ### `.blue-sidebar-menu-horizontal-on-open` Use this inside of the sidebar to make menus act like horizontal menus when the sidebar is open. Designed for the `IconMenuItem` component. But might be useful for other scenarios aswell. ### `.blue-sidebar-menu-vertical-on-open` If you want to change direction inside of `.blue-sidebar-menu-horizontal-on-open` back to vertical, use `.blue-sidebar-menu-vertical-on-open`. Might be useful for dropdowns. ## Tabs Tabs just with HTML and CSS, no JavaScript needed. The state is managed by the radio input elements. The classes by Blue Web only provide styles for fundamental functionality. ```html
Tab content 1
Tab content 2
Tab content 3
``` ### Bootstrap Tabs Nav style You should combine them with `.nav.nav-tabs` and `.nav-link` by Bootstrap. ```html ``` ### Bootstrap Underline Nav style ```html ``` ### Bootstrap Underline Nav style customized You can customize the look more by overriding the CSS variables coming from Bootstrap. Blue Web also added some additional CSS variables. ```html ``` ## Text and Icons ### `.blue-page-header` or `.page-header` In previous versions of Bootstrap, `.page-header` was a class that could be used to add a border to the bottom of a page header. Unfortunately his class was removed in Bootstrap 5, so it's now part of Blue Web CSS. ```html
Example headline
``` ### `.blue-icon` or `.bi` Vertically alignment, especially for Bootstrap Icons. ## Tooltip ### `.blue-tooltip` CSS only solution for tooltips. For accessibility reasons, only wrap around interactive elements like buttons or links. To use, add the `data-tooltip` attribute to the wrapping element. ```html
``` ### `.blue-tooltip-up`, `.blue-tooltip-down`, `.blue-tooltip-start`, `.blue-tooltip-end` Change the position of the tooltip. To be used together with `data-tooltip`. ```html
``` ### `.blue-tooltip-content` This is how you can customize the tooltip content with HTML. ```html
``` ## Visibility ### `.blue-opacity-hover`, `.blue-opacity-hover-content-active`, `.blue-opacity-hover-content-default` With `.blue-opacity-hover` you can hide things by default and let them appear when the user hovers the area around it or focuses an element inside. This way you can simplify the UI a bit and make controls disappear when they are not needed. On touch screens the elements will always be visible. Usage: ```html
Hover here to see a button
``` ### `.blue-d-hover`, `.blue-d-hover-content-active`, `.blue-d-hover-content-default` `.blue-d-hover` is similar to `.blue-opacity-hover`, but the elements will disappear and appear with the `display` property. It is ideal if you want to replace something with something else when the user hovers. On the example I used it to change the edit and delete icons from lineout to filled when hovering. Usage: ```html ``` ## Actions Combination of toolbar and a dropdown menu. Items in toolbar will only be shown if there is enough space. Otherwise they will be visible in the dropdown menu. JavaScript detects if space is changing and rearranges. ### Demo 1: Use Menu Items of Blue Web and Dropdown with Popover and Anchor Positioning ```html ``` ### Demo 2: Use Menu Items of Blue Web and Details [HTML Details](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/details) will be used for the dropdown menu. Event handler in `actions.ts` automatically closes the Menu when clicking outside. ```html ``` The JavaScript function `init` returns an object with the function `destroy()`. When you execute it, the `ResizeObserver` will be disconnected and global event listeners will be removed. Try to click the button. It will destroy the actions from above. ```html ``` ### Demo 2: Use Bootstrap Button Groups ```html ``` ## Color Mode Use `color-mode.js` for better support for [Bootstrap's color modes](https://getbootstrap.com/docs/5.3/customize/color-modes/). The script automatically detects if the user uses light or dark mode and sets the `data-bs-theme` attribute to the document element (``). It also updates it if the color mode changes. It also exports these functions: - `getStored()` - Returns what is stored (`"light"`, `"dark"` or `null`). - `getPreferred()` - Returns current color mode (`"light"` or `"dark"`). - `set(colorMode: string)` - Let's you set the color mode. - `init()` - Let's you reinitialize manually. Will automatically executed when the script loaded and when the color mode changes. ### Color Mode Switch Example about, how you could create a color mode switch. ```html
``` ## Dialog These functions are meant as a nicer alternative to the native `alert`, `confirm` and `prompt` functions. They are not meant to be used as a replacement for more complex modals. ### Functions #### Verify ```html ``` #### Tell ```html ``` #### Ask ```html ``` ## Progress A "fake" progress bar that will appear fixed at the top of the page. ### Start and stop ```html ``` ```html ``` ### Add to custom element You can customize the element further by setting a custom ID, parent element and position class name. This allows you to attach the progress element to some other element than the body. ```html
Add progress bar to this
``` ## ReadView A Web Component that displays a read view of its content and allows the user to switch to an edit view. ### Demo #### Basic usage ```html Link Click to edit the link
``` #### Disabled ```html Link This one is disabled ``` ## SideLayout ### Simple example Layout with a sidebar as a Web Component. ```html
Header
Side
Main
``` ### Example with Blue Web (Bootstap) classes ```html
Side
``` ### Example with Tailwind CSS classes ```html
Side
Hello World
``` import UtilsDemo from "$/components/UtilsDemo.tsx" ## Utils ### Usage You can import functions inidivually like this: ```js import { startLoading } from "blue-web/dist/js/utils.js" ``` or like this: ```html ``` `utils.js` is provided as ESM, so you can use it as a module in the browser: ```html ``` ### Required markup Some of the util functions to show status information require to have some HTML elements available. ```html
``` ### JavaScript Functions ## View Transition API [View Transition API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API) is not a Blue Web API, but a native Web API provided by browsers. It allows you to easily animate transitions between different UI states. ```html
``` ## Typography Since Blue Web builds on top of Bootstrap, you should also check out [their section about typography](https://getbootstrap.com/docs/5.3/content/typography/). ### Inter as font family Blue Web is configured to use [Inter](https://rsms.me/inter/) with some preset font features. The required font files aren't included with Blue Web. [Please take a look at the documentation by Inter](https://github.com/rsms/inter?tab=readme-ov-file#using--installing-inter) to find out how to install them. As fallback, when Inter couldn't be loaded, the default font family setting by Bootstrap (`$font-family-sans-serif`) will be used, which is a native font stack that selects the best font-family for each OS and device.