The UI component library has components to build web front-ends.
Add this to your gramex.yaml. Now, the UI component library is available at /ui/.
import:
ui:
path: $GRAMEXAPPS/ui/gramex.yaml
YAMLURL: $YAMLURL/ui/
Change the $YAMLURL/ui/ to any path you want to expose the UI components at.
The UI component library ships with pre-defined Bootstrap themes from Bootswatch and Bootstrap Themes Guide.
Explore theme gallery
You can import them in your style.scss. For example:
// Include any one of these lines in your .scss file
@import "theme/bootstrap5"; // Bootstrap 5 default theme
@import "theme/default"; // Bootstrap 4 default theme
@import "theme/bootswatch/slate"; // Bootstrap 4 theme
@import "theme/themes-guide/fesca"; // Bootstrap 4 theme
Or you can link to these directly. For example:
<!-- Include any one of these links in your .scss file -->
<link rel="stylesheet" href="ui/theme/bootstrap5.scss" />
<link rel="stylesheet" href="ui/theme/default.scss" />
<link rel="stylesheet" href="ui/theme/bootswatch/slate.scss" />
<link rel="stylesheet" href="ui/theme/themes-guide/fresca.scss" />
You can customize themes by adding Bootstrap variables to the URL. For example:
<link
rel="stylesheet"
href="ui/theme/default.scss?primary=maroon&body-bg=lavender"
/>
Try the custom theme
You can also customize themes by adding these to your style.scss file. For example:
$primary: maroon;
$body-bg: lavender;
@import "theme/default.scss";
See the full list of Bootstrap variables.
Customize with a theme builder
You can add custom colors to the $theme-colors map in your style.scss file. For example:
$theme-colors: (
"accent1": coral,
"accent2": #3cb371,
)
@import "theme/default.scss";
You can now use .bg-accent1, .text-accent1, .btn-accent1, .border-accent1, etc., and
similarly for accent2.
UI Libraries are deprecated since Gramex 1.84. Use jsDelivr instead.
The Gramex UI component library ships commonly used UI libraries.
These are accessible via /ui/package@version/file.js. For example, /ui/d3@7/dist/d3.min.js.
Prior to Gramex 1.84, these libraries were npm installed on Gramex.
After Gramex 1.84, these URLs redirect to cdn.jsdelivr.net.
For example, /ui/d3@7/dist/d3.min.js redirects to https://cdn.jsdelivr.net/npm/ui/d3@7/dist/d3.min.js.
Explore UI libraries on CDN
Bootstrap provides the following absolute font-size classes:
.display-1: 6rem.display-2: 5.5rem.display-3: 4.5rem.display-4: 3.5rem.h1: 2.5rem.h2: 2rem.h3: 1.75rem.h4: 1.5rem.h5: 1.25rem.h6: 1remGramex UI components adds the following relative font-size classes that make a font smaller:
.sm1: 80% smaller (same as .small).sm2: 66.67% smaller.sm3: 50% smaller.sm4: 33.33% smaller.sm5: 25% smaller.sm6: 16.67% smaller.text-middle aligns text vertically to middle
Normal text is aligned to the top
.ls-1 sets letter-spacing: 0.05em.ls-2 sets letter-spacing: 0.10em.ls-3 sets letter-spacing: 0.20em.ls-4 sets letter-spacing: 0.30em.ls-n1 sets letter-spacing: -0.025em..ls-n2 sets letter-spacing: -0.05em..ls-n3 sets letter-spacing: -0.10em..ls-n4 sets letter-spacing: -0.20em..lh-1 sets line-height: 1.lh-2 sets line-height: 1.1.lh-3 sets line-height: 1.25.lh-4 sets line-height: 2.opacity-90 sets opacity: 90%.opacity-80 sets opacity: 80%.opacity-70 sets opacity: 70%.opacity-60 sets opacity: 60%.opacity-50 sets opacity: 50%.opacity-40 sets opacity: 40%.opacity-30 sets opacity: 30%.opacity-20 sets opacity: 20%.opacity-10 sets opacity: 10%.border-2 sets border-width: 2px.
.border .border-2.border-top, .border-right, .border-bottom and .border-left set the respective border-width to 1px.
.border-top.border-right.border-bottom.border-left.border-top-0, .border-right-0, .border-bottom-0 and .border-left-0 set the respective border-width to 0px.
.border-top-0.border-right-0.border-bottom-0.border-left-0.shadow adds a shadow to a block element. For example:
.text-shadow adds a text shadow to inline text. For example:
Take this sample background image:
.bg-no-repeat sets background-repeat: no-repeat, which creates only one copy of the background image.
.bg-center centers the background image.
Background positioning utilities determine the overall positioning. .bg-tl stands for
background-top-left. You can use bg-(top/center/bottom)-(left/center/right).
USe with bg-no-repeat as follows:
.bg-tl.bg-tc.bg-tr.bg-cl.bg-cc.bg-cr.bg-bl.bg-bc.bg-br.bg-space sets background-repeat: space, which distributes space evenly between background image copies.
.bg-round sets background-repeat: round, which ensures that the background image is not cut off (but may shrink).
.bg-cover sets background-size: cover. The background image will completely fill the element.
.bg-contain sets background-size: contain. The background image will completely fit in the element.
.bg-fixed sets background-size: fixed. The background will scroll with the page.
.bg-parellax sets background-size: parellax. The background will scroll with the page. This is
the same as .bg-center .bg-no-repeat .bg-fixed and .bg-cover.
.gradient-* classes darken colors in a specified direction.
.gradient-tl stands for gradient-top-left.
You can use gradient-(top/center/bottom)-(left/center/right).
Here’s an example combining the gradients with different .bg- classes:
.gradient-tl.gradient-tc.gradient-tr.gradient-cl.gradient-cc.gradient-cr.gradient-bl.gradient-bc.gradient-br.gradient-light makes it a lightening gradient.
Here’s an example combining the gradients with different .bg- classes:
.gradient-light .gradient-tl.gradient-light .gradient-tc.gradient-light .gradient-tr.gradient-light .gradient-cl.gradient-light .gradient-cc.gradient-light .gradient-cr.gradient-light .gradient-bl.gradient-light .gradient-bc.gradient-light .gradient-brAdd class="round" to add full rounded corners to any shape. For example:
.btn.btn-primary
.round.btn.btn-primary
Add class="border-radius-{size} to control the size of the rounded corners.
.border-radius-xl
.border-radius-lg
.border-radius
.border-radius-sm
.no-border-radius
.ripple adds a ripple effect to elements when clicked. Click to test:
These utility classes override the color of any element on :hover, :focus and :active –
typically buttons and links. The classes are defined for each theme color.
.hover-bg-{color}, .focus-bg-{color} and .active-bg-{color} for background color..hover-fg-{color}, .focus-fg-{color} and .active-fg-{color} for foreground color.Hover color classes set the color when you hover over an element. Hover to test:
class="hover-bg-primary hover-fg-light"class="hover-bg-dark hover-fg-light"class="hover-bg-light hover-fg-danger"Focus color classes set the color when you focus on an element. Click to test:
class="focus-bg-primary focus-fg-light"class="focus-bg-dark focus-fg-light"class="focus-bg-light focus-fg-danger"Active color classes set the color when you’re clicking on an element. Click to test:
class="active-bg-primary active-fg-light"class="active-bg-dark active-fg-light"class="active-bg-light active-fg-danger"class="cursor-pointer" adds a cursor: pointer to any element. Use
non-clickable element made clickable using JavaScript.class="cursor-default" adds cursor: default.class="pointer-events-none" sets pointer-events: none.
This disables click and hover events. It’s useful on SVG text labels to pass clicks to the
shape behind it..overlay-black and .overlay-white overlays a dark or light layer on top of a relatively
positioned element.
.pos-* classes set the absolute position of elements.
.pos-tl stands for position: top-left. It sets top: 0 and left: 0.
You can use pos-(top/center/bottom)-(left/center/right).
Here’s an example of all .pos- classes inside a .position-relative block:
.h-full sets min-height: 100vh. To ensure that a page background occupies full height of the screen, use:
<body class="h-full"></body>
.z-9 sets z-index: 9000. Use it to place an element on top of others
.arrow-<theme-color> creates an arrow shape. Add .h1, … .h6 or .display-1 .. .display-4
to control the height.
Add .arrow-tail to add a tail.
.divider adds a divider. For example, <div class="divider"></div> creates this divider:
Add .border-primary, etc to change the divider color. For example:
<div class="divider border-primary"></div>
creates this divider:
You can add any text inside the divider. For example:
<div class="divider">Text</div>
<div class="divider border-dark">
<i class="fab fa-2x fa-twitter me-2"></i> Icons
</div>
<div class="divider border-primary">
<div class="btn btn-primary round">Buttons</div>
</div>
.tail-* adds a tail to a container. .tail-tl adds a tail on the top side left position.
You can use tail-{side}-{position}. For example:
You can combine tails with .border, .round, .shadow and other styles. For example:
The following classes are deprecated:
.underline: use .border-bottom.slider: use .custom-range.switch: use .custom-switch.border-top-1, .border-right-1, .border-bottom-1 and .border-left-1. These are rarely used.