Forge UI is a Vue.js component library and CSS framework. Vue components are reusable, with customizable templates. CSS framework components are kept minimal to avoid the need for style overwrites or excessive configuration inherent in many modern frameworks.
ForgeUI CSS components do not require JavaScript, and can be used freely once the ForgeUI CSS has been included on the page.
Most of the styling can be configured through CSS variables. Global CSS variables are listed below, while component-specific variables can be found alongside in the documentation for each component.
All CSS variables are flagged as !default in ForgeUI, so you can override them at any point.
Variable | Type | Default Value | Description |
---|---|---|---|
$primary-color | Color | #2199e8 | Used throughout styling whenever the primary class can be appended to an element. |
$secondary-color | Color | #777 | Used throughout styling whenever the secondary class can be appended to an element. |
$success-color | Color | #3adb76 | Used throughout styling whenever the success class can be appended to an element. |
$warning-color | Color | #ffae00 | Used throughout styling whenever the warning class can be appended to an element. |
$alert-color | Color | #ec5840 | Used throughout styling whenever the alert class can be appended to an element. This color is also used to color input borders and error messages when the input value is invalid. |
$white | Color | #fefefe | Used by default as the body background color. Change this value when you want the default white color to change site-wide. To change only the body background color, use the $body-background variable. |
$light-gray | Color | #e6e6e6 | Used by default as the default pill background color. Change this value when you want the default light gray color to change site-wide. To change only the pill default background color, use the $pill-background-color-default variable. |
$medium-gray | Color | #cacaca | Placeholder for a medium gray variable; currently unused. |
$dark-gray | Color | #8a8a8a | Used by default as the default tab nav color. Change this value when you want the default dark gray color to change site-wide. To change only the tab nav color, use the $tab-nav-font-color variable. |
$black | Color | #0a0a0a | Used by default as the body font color and the base for transparent overlay colors. Change this value when you want the default black color to change site-wide. To change only body font color or overlay base colors, use the appropriate variable. |
$overlay-opacity | Number | 0.6 | The opacity of various overlays in ForgeUI; used in conjunction with base colors to add alpha transparency for overlays. |
$global-width | Number | rem-calc(1200) | The default maximum column width. |
$body-background | Color | $white | The default body background color. |
$global-margin | Number | 1rem | Used throughout the site to vertically space out various content elements. |
$global-padding | Number | 1rem | Used throughout the site to add padding to various elements. |
$global-radius | Number | 2px | The default border radius. |
Returns an equivalent size in rem.
Argument | Type | Required | Description |
---|---|---|---|
sizeInPx | Integer | true | The size in px to convert to rem. |
p {
font-size: rem-calc(16); // 1rem
}
h1 {
font-size: rem-calc(24); // 1.5rem
}
Simple clearfix mixin.
.container {
@include .clearfix();
img {
float: left;
}
}
ForgeUI uses a set of media query mixins modeled after the type of device you want to apply styling to. ForgeUI is mobile first, so mobile styling should be applied first, and overrides for larger screen sizes should be applied with media queries.
Please use the small-only media query sparingly!
@include small-only() {
// mobile only styling
}
@include medium-up() {
// tablet and larger styling
}
@include medium-only() {
// tablet only styling
}
@include large-up() {
// desktop and larger styling
}
ForgeUI also has a full list of visibility helpers that can be used anywhere. The visibility classes only apply display: none; where appropriate, never any other display class. So these utilities are usable on elements with any type of display.
<div class="alert-box secondary">
<ul>
<li class="show-small">This text shows on <em>small</em> screens</li>
<li class="show-medium-up">This text shows on <em>medium or larger</em> screens</li>
<li class="show-medium">This text shows on <em>medium</em> screens</li>
<li class="show-large">This text shows on <em>large</em> screens</li>
<li class="hide-small">This text hides on <em>small</em> screens</li>
<li class="hide-medium">This text hides on <em>medium</em> screens</li>
<li class="hide-large">This text hides on <em>large</em> screens</li>
</ul>
</div>
Variable | Type | Default Value | Description |
---|---|---|---|
$breakpoint-medium | Number | 600px | The default breakpoint for medium screens. |
$breakpoint-large | Number | 1200px | The default breakpoint for large screens. |
ForgeUI sports the following helpers for quick and common CSS additions:
Class | Description |
---|---|
.show-small | Show for small screens only. |
.show-medium | Show for medium screens only. |
.show-medium-up | Show for medium and large screens. |
.show-large | Show for large screens. |
.hide-small | Hide for small screens. |
.hide-medium | Hide for medium screens. |
.hide-medium-up | Hide for medium and large screens. |
.hide-large | Hide for large screens. |
.text-left | Left align text. |
.text-right | Right align text. |
.text-center | Center align text. |
.uppercase | Capitalize text. |
.float-left | Float element left. |
.float-right | Float element right. |
p. Lorem Ipsum
small. Lorem Ipsum
<h1>h1. Lorem Ipsum</h1>
<h2>h2. Lorem Ipsum</h2>
<h3>h3. Lorem Ipsum</h3>
<h4>h4. Lorem Ipsum</h4>
<h5>h5. Lorem Ipsum</h5>
<h6>h6. Lorem Ipsum</h6>
<p>p. Lorem Ipsum</p>
<p><small>small. Lorem Ipsum</small></p>
<p><a href="#">Link</a></p>
Variable | Type | Default Value | Description |
---|---|---|---|
$body-font-color | Color | $black | The default body font color. |
$body-font-family | String | 'Open Sans', sans-serif | The default body font family. |
$global-weight-normal | String or Number | normal | The default font weight for normal text. |
$global-weight-bold | String or Number | bold | The default font weight for bold text. |
$base-font-size | Number | 16 | Used as the base font size when calculating rem via the rem-calc() function. |
$paragraph-font-family | String | inherit | Paragraph font family. |
$paragraph-font-weight | String or Number | normal | Paragraph font weight. |
$paragraph-font-size | Number | $base-font-size | Paragraph font size. |
$paragraph-line-height | Number | 1.6 | Paragraph line height. |
$paragraph-margin-bottom | Number | 20 | Paragraph bottom margin. |
$paragraph-text-rendering | String | optimizeLegibility | Paragraph text rendering. |
$header-font-family | String | 'Hind', sans-serif | Heading font family. |
$header-font-weight | String or Number | bold | Header font weight. |
$header-font-style | String | normal | Header font style |
$header-font-color | Color | #222 | Header font color. |
$header-line-height | Number | 1.4 | Header line height. |
$header-top-margin | Number | .2rem | Header top margin. |
$header-bottom-margin | Number | .5rem | Header bottom margin. |
$header-text-rendering | String | optimizeLegibility | Header text rendering. |
$h1-font-size | Number | 44 | H1 font size. |
$h2-font-size | Number | 37 | H2 font size. |
$h3-font-size | Number | 27 | H3 font size. |
$h4-font-size | Number | 23 | H4 font size. |
$h5-font-size | Number | 18 | H5 font size. |
$h6-font-size | Number | $base-font-size | H6 font size. |
$small-font-size | Number | 60% | Font size for small elements nested inside a header. |
$small-font-color | Color | scale-color($header-font-color, $lightness 35%) | Small element font color. |
$anchor-text-decoration | String | none | Anchor text decoration. |
$anchor-font-color | Color | $primary-color | Anchor font color. |
$anchor-font-color-hover | Color | scale-color($primary-color, $lightness -14%) | Anchor hover font color. |
$hr-border-width | Number | 1px | HR size. |
$hr-border-style | String | solid | HR border style. |
$hr-border-color | Color | $medium-gray | HR border color. |
$hr-margin | Number | 20px | HR margins. |
So. Many. Buttons.
Each button needs a button class. The following classes can be mixed and matched to change the type of button:
<div class="row">
<div class="small-12 large-6 column">
<div>
<button type="button" class="button">Button</button>
<button type="button" class="button secondary">Button</button>
<button type="button" class="button success">Button</button>
<button type="button" class="button warning">Button</button>
<button type="button" class="button alert">Button</button>
</div>
<div>
<button type="button" class="button tiny">Button</button>
<button type="button" class="button small">Button</button>
<button type="button" class="button">Button</button>
<button type="button" class="button large">Button</button>
</div>
<div>
<button type="button" class="button hollow">Button</button>
<button type="button" class="button hollow secondary">Button</button>
<button type="button" class="button hollow success">Button</button>
<button type="button" class="button hollow warning">Button</button>
<button type="button" class="button hollow alert">Button</button>
</div>
</div>
<div class="small-12 large-6 column">
<div>
<button type="button" class="button expand">Button</button>
</div>
<div>
<button type="button" class="button expand hollow">Button</button>
</div>
<div>
<button type="button" class="button expand tiny">Button</button>
<button type="button" class="button expand small">Button</button>
<button type="button" class="button expand">Button</button>
<button type="button" class="button expand large">Button</button>
</div>
</div>
</div>
Variable | Type | Default Value | Description |
---|---|---|---|
$button-color | Color | #fefefe | Button text color. |
$button-font-size | Number | 14 | Button font color. |
$button-font-family | String | inherit | Button font family. |
$button-line-height | Number | 1 | Button line height. |
$button-hover-darken | Number | 10% | The amount to darken the button background color on hover. |
$button-border-color | Color | transparent | Button border color. |
$button-border-size | Number | 1px | button border size. |
$button-border-style | String | solid | Button border style. |
$button-hollow-border-size | Number | 1px | Border size for hollow buttons. |
$button-hollow-border-style | String | solid | Button border style for hollow buttons. |
$button-radius | Number | $global-radius | Button border radius. |
$button-padding | Number | 0.85em 1em | Button padding. |
$button-margin | Number | 0 0 1rem 0 | Button margins. |
$button-background-color-default | Color | $primary-color | Default button background color. |
$button-background-color-secondary | Color | $secondary-color | Secondary button background color. |
$button-background-color-success | Color | $success-color | Success button background color. |
$button-background-color-warning | Color | $warning-color | Warning button background color. |
$button-background-color-alert | Color | $alert-color | Alert button background color. |
$button-background-color-hover-default | Color | darken($button-background-color-default, $button-hover-darken) | Default button hover background color. |
$button-background-color-secondary-hover | Color | darken($secondary-color, $button-hover-darken) | Secondary button hover background color. |
$button-background-color-success-hover | Color | darken($success-color, $button-hover-darken) | Success button hover background color. |
$button-background-color-warning-hover | Color | darken($warning-color, $button-hover-darken) | Warning button hover background color. |
$button-background-color-alert-hover | Color | darken($alert-color, $button-hover-darken) | Alert button hover background color. |
$button-tiny-font-size | Number | 10 | Tiny button font size. |
$button-small-font-size | Number | 12 | Small button font size. |
$button-large-font-size | Number | 20 | Large button font size. |
Pills are a simple way to highlight a portion of text. They are inline elements and can be modified by any of the color classes
<ul class="inline">
<li><span class="pill">default</span></li>
<li><span class="pill primary">primary</span></li>
<li><span class="pill secondary">secondary</span></li>
<li><span class="pill success">success</span></li>
<li><span class="pill warning">warning</span></li>
<li><span class="pill alert">alert</span></li>
</ul>
Variable | Type | Default Value | Description |
---|---|---|---|
$pill-radius | Number | $global-radius | Pill border radius. |
$pill-background-color-default | Color | $light-gray | Default pill background color. |
Grid columns should be nested under a row element. Columns can be separated using a 12-column system with small, medium, and large prefixes for responsive changes in column flow. All columns should include the column class.
<div class="row">
<div class="small-12 column">12</div>
</div>
<div class="row">
<div class="small-1 column">1</div>
<div class="small-2 column">2</div>
<div class="small-3 column">3</div>
<div class="small-6 column">6</div>
</div>
<div class="row">
<div class="small-4 column">4</div>
<div class="small-8 column">8</div>
</div>
Variable | Type | Default Value | Description |
---|---|---|---|
$grid-row-width | Number | $global-width | The maximum width of a grid row. Rows that are shorter than their prent element will be horizontally centered. |
$grid-column-count | Number | 12 | The maximum number of columns per row. |
$grid-column-gutter | Number | 30px | The spacing between columns. Each row will include negative left and right margins equal to half of this value. |
The block grid uses a row parent just like the normal grid, but instead of setting the column size on the column, it is set with a small-up-X, medium-up-X, or large-up-X class, where X represents the number of columns before each line break, and is a number 1 through $block-grid-column-count (8 by default).
<div class="row small-up-8">
<div class="column">1</div>
<div class="column">2</div>
<div class="column">3</div>
<div class="column">4</div>
<div class="column">5</div>
<div class="column">6</div>
<div class="column">7</div>
<div class="column">8</div>
<div class="column">9</div>
<div class="column">10</div>
<div class="column">11</div>
<div class="column">12</div>
<div class="column">13</div>
<div class="column">14</div>
<div class="column">15</div>
<div class="column">16</div>
<div class="column">17</div>
<div class="column">18</div>
<div class="column">19</div>
<div class="column">20</div>
</div>
Variable | Type | Default Value | Description |
---|---|---|---|
$block-grid-column-count | Number | 8 | The maximum number of columns in a block grid. |
To use any of the transitions, simple add the keyword to the transition name to the element you will be showing/hiding as described in the Vue documentation.
The following transitions are available as part of ForgeUI:
<ul class="inline">
<li>One Item</li>
<li>Two Item</li>
<li>Red Item</li>
<li>Blue Item</li>
</ul>
Variable | Type | Default Value | Description |
---|---|---|---|
$list-inline-padding | Number | $global-padding | Inline list padding. |
$list-inline-spacing | Number | rem-calc(8) | Inline list element horizontal spacing. |
The icon component is meant for simple rendering of SVG icons and has built with custom icons in mind.
The icon component uses the xlink:href attribute to point at a symbol in an SVG store elsewhere on the page. For instructions on setting up an SVG store, see this blog post.
ForgeUI also comes with a basic set of icons you can use in lieu of a custom set of SVGs. To use the ForgeUI icons, modify the source your task runner looks for SVG files in, passing along the ForgeUI include paths to gulp.src.
/* gulpfile.js */
var gulp = require('gulp');
var svgstore = require('gulp-svgstore');
var inject = require('gulp-inject');
gulp.task('default', function () {
// use 'forge-ui/includePaths' to create a glob that includes the ForgeUI icons
var svgs = gulp.src(require('forge-ui/includePaths').icons).pipe(svgstore({ inlineSvg: true }));
function fileToString(filePath, file) {
return file.contents.toString();
}
return gulp.src('./index.html')
.pipe(inject(svgs, { transform: fileToString }))
.pipe(gulp.dest('./'));
});
<icon name="home" :size="40"></icon>
<icon name="home"></icon>
<icon name="home" :size="10"></icon>
new Vue({
el: '#icon_demo'
});
Prop | Type | Required | Default | Description |
---|---|---|---|---|
name | Boolean | false | false | Set to true to display the close button in the top right corner. |
size | Number | false | 20 | the size of the icon. |
More icons coming soon !!!
The alert component is designed to have it's methods accessed via ref in a parent component. Calling the appropriate method attached to the ref will render an error in the box. Setting the error as a new type will clear the previous errors in the alert.
<alert ref="myAlert" :can-close="true"></alert>
<div class="row">
<div class="small-12 medium-5 column">
<f-input type="text" label="Alert Message" v-model="alertMessage"></f-input>
</div>
<div class="small-12 medium-5 column">
<f-select label="Method" v-model="selectedMessageType" :options="messageTypes" :required="true"></f-select>
</div>
<div class="small-12 medium-2 column">
<button type="button" class="button expanded inline-form" @click="newMessage()">Send</button>
</div>
</div>
new Vue({
el: '#alert_demo',
data: {
alertMessage: '',
selectedMessageType: 'message',
messageTypes: [
{ value: 'message', label: 'vm.$refs.myAlert.message()' },
{ value: 'primary', label: 'vm.$refs.myAlert.primary()' },
{ value: 'secondary', label: 'vm.$refs.myAlert.secondary()' },
{ value: 'success', label: 'vm.$refs.myAlert.success()' },
{ value: 'warning', label: 'vm.$refs.myAlert.warning()' },
{ value: 'alert', label: 'vm.$refs.myAlert.alert()' },
]
},
methods: {
newMessage() {
this.$refs.myAlert[this.selectedMessageType](this.alertMessage);
}
}
});
Prop | Type | Required | Default | Description |
---|---|---|---|---|
canClose | Boolean | false | false | Set to true to display the close button in the top right corner. |
transition | String | false | fade | The transition to use when toggling visibility on the alert. |
Method | Description |
---|---|
message(message) | Display a callout message with no additional color class. |
primary(message) | Display a callout message with the primary color class. |
secondary(message) | Display a callout message with the secondary color class. |
success(message) | Display a callout message with the success color class. |
warning(message) | Display a callout message with the warning color class. |
alert(message) | Display a callout message with the alert color class. |
SCSS Variable | Type | Default Value | Description |
---|---|---|---|
$alert-background-color-default | Color | transparent | Alert box background color. |
$alert-background-color-primary | Color | #d7ecfa | Primary alert box background color. |
$alert-background-color-secondary | Color | #eaeaea | Secondary alert box background color. |
$alert-background-color-success | Color | #e1faea | Success alert box background color. |
$alert-background-color-warning | Color | #fff3d9 | Warning alert box background color. |
$alert-background-color-alert | Color | #f7e4e1 | Alert alert box background color. |
$alert-border-color | Color | rgba(10, 10, 10, 0.25) | Alert box border color. |
$alert-message-padding | Number | 4px | Vertical spacing between alert box messages. |
The Tabs component acts as a wrapper for any number of Tab components. Minimal configuration is needed to render a set of tabs, so long as the component is registered to vue.
Some tab content
Some content for another tab
Even more tab content!
<tabs>
<tab heading="Foo" :selected="true">
<p>Some tab content</p>
</tab>
<tab heading="Bar">
<p>Some content for another tab</p>
</tab>
<tab heading="Baz">
<p>Even more tab content!</p>
</tab>
</tabs>
new Vue({
el: '#tabs_demo'
});
Prop (tab) | Type | Required | Default | Description |
---|---|---|---|---|
heading | String | true | false | The text to display in the clickable tab navigation. |
selected | Boolean | false | false | Activates the tab on mount when set to true. |
SCSS Variable | Type | Default Value | Description |
---|---|---|---|
$tab-content-padding | Number | $global-padding | Spacing between tab content and tab nav. |
$tab-nav-font-color | Color | $dark-gray | Inactive tab nav font color. |
$tab-nav-font-color-hover | Color | $body-font-color | Hovered tab nav font color. |
$tab-nav-font-color-active | Color | $body-font-color | Active tab nav font color. |
$tab-nav-border-color | Color | $body-font-color | Tab nav border color. |
$tab-nav-padding | Numbers | 4px 10px | Tab nav item padding. |
A simple modal dialog.
some super awesome modal content
<button type="button" class="button" @click="openModal()">Open Modal</button>
<modal ref="myModal">
<div slot="header">
<h3>Look, a Modal!</h3>
</div>
<div slot="content">
<p>some super awesome modal content</p>
<button type="button" class="button" @click="closeModal()">Close</button>
</div>
</modal>
new Vue({
el: '#modal_demo',
methods: {
openModal() {
this.$refs.myModal.open();
},
closeModal() {
this.$refs.myModal.close();
}
}
});
Prop | Type | Required | Default | Description |
---|---|---|---|---|
modalSize | String | false | full | The size of the modal. Can be small or full. |
transition | String | false | zoom-out | the modal show/hide transition. |
Method | Description |
---|---|
open() | Open the modal. |
close() | Close the modal. |
SCSS Variable | Type | Default Value | Description |
---|---|---|---|
$modal-size-default | Number | 580px | Width for full sized modals. |
$modal-size-small | Number | 300px | Width for small sized modals. |
$modal-padding | Number | $global-padding | Modal padding. |
$modal-background-color | Color | $body-background | Modal background color. |
$modal-overlay-color | Color | rgba($black, $overlay-opacity) | Modal overlay background color. |
A simple prompt component meant to replace the native prompt and confirm methods. This will allow you to style the dialog to match your site and prevent users from asking the browser to suppress further dialogs.
This component is meant to get input back from the user. If you simply need to notify the user of something, use an alert component to display the information and it's canClose property if the information should be dismissable.
With great power comes great responsibility. These dialogs cannot be suppressed by the browser, so take care not to inundate the user with an endless stream of repeditive dialogs.
Both prompt methods take an options object supporting the following parameters:
<prompt ref="myPrompt"></prompt>
<button type="button" class="button" v-on:click="prompt('ask')">vm.$refs.myPrompt.ask()</button>
<button type="button" class="button" v-on:click="prompt('confirm')">vm.$refs.myPrompt.confirm()</button>
new Vue({
el: '#prompt_demo',
methods: {
prompt(method) {
this.$refs.myPrompt[method]({
question: 'Judge me by my size, do you?',
yes: function (answer) {
// if method is 'ask',
// the dialog input value will be passed as the first argument
},
no: function () {
// the prompt will close itself,
// but you can use this option to trigger side effects
}
});
}
}
});
Method | Description |
---|---|
ask(options) | This provides a text input to the user to enter a custom answer similar to the native prompt() method. When clicking the confirm button the dialog input will be validated before calling the provided yes() function. |
confirm(options) | This provides a yes or no dialog similar to the native confirm() method. |
SCSS Variable | Type | Default Value | Description |
---|---|---|---|
$prompt-width | Number | 400px | Prompt modal width. |
$prompt-padding | Number | $global-padding | Prompt modal padding. |
$prompt-background-color | Color | $body-background | Prompt modal background color. |
$prompt-overlay-color | Color | rgba($black, $overlay-opacity) | Prompt overlay background color. |
The snackbar component offers up an alternative alert style that shows a fixed position message for a short dureation before closing itself.
<snackbar ref="mySnackbar" :position="currentPosition"></snackbar>
<f-form :ajax="true" @submit="newToast">
<div class="row">
<div class="small-12 column">
<f-radio label="Position" v-model="currentPosition" :options="options" name="positioningOptions"><f-radio>
</div>
<div class="small-12 medium-5 column">
<f-input type="text" label="Message" v-model="toast" :required="true"></f-input>
</div>
<div class="small-12 medium-2 column">
<button type="submit" class="button expanded inline-form">Toast!</button>
</div>
</div>
</f-form>
new Vue({
el: '#snackbar_demo',
data: {
toast: '',
currentPosition: 'bottom left',
options: [
{ name: 'topOption', label: 'top', value: 'top' },
{ name: 'bottomOption', label: 'bottom', value: 'bottom' },
{ name: 'leftOption', label: 'left', value: 'left' },
{ name: 'rightOption', label: 'right', value: 'right' },
{ name: 'topLeftOption', label: 'top left', value: 'top left' },
{ name: 'topRightOption', label: 'top right', value: 'top right' },
{ name: 'bottomLeftOption', label: 'bottom left', value: 'bottom left' },
{ name: 'bottomRightOption', label: 'bottom right', value: 'bottom right' }
]
},
methods: {
newToast() {
if (this.toast !== '') {
this.$refs.mySnackbar.toast(this.toast, () => alert('bar'));
}
}
}
});
Prop | Type | Required | Default | Description |
---|---|---|---|---|
timeout | Number | false | 4000 | The delay before automatically closing the snackbar. Set to zero to disable automatically closing snackbar. |
actionLabel | String | false | Go | The label for the action button if an action is provided as part of the toast() call. |
transition | String | false | fade | The transition registered to vue to use when showing/hiding the snackbar. |
position | String | false | bottom left | The position of the snackbar: top, bottom, left, right, top left, bottom left, top right, bottom right |
Method | Description |
---|---|
toast(message, action) | Show the snackbar with the provided message. If a function is provided to action, a button will be shown in the snackbar that calls the provided function. If a string is provided to action, the button will be rendered as a link with the action used for the href. |
close() | Close the snackbar. |
SCSS Variable | Type | Default Value | Description |
---|---|---|---|
$snackbar-background-color | Color | $dark-gray | Snackbar background color. |
$snackbar-font-color | Color | $white | Snackbar message font color. |
$snackbar-padding | Number | 1rem 1.5rem | Snackbar box padding. |
$snackbar-border-radius | Number | $global-radius | Border radius for the snackbar box. |
The fForm component automatically validates it's child components on form submission and can be configured use default submission behavior or execute a callback function is inline or AJAX behavior is more desirable.
If there are any errors in the configured validation errors will be triggered on inputs and the form will not submit or execute the submitCallback.
<alert ref="myAlert" :can-close="true"></alert>
<f-form :ajax="true" @submit="showMessage">
<f-input type="text" v-model="message" :required="true"></f-input>
<button type="submit" class="button">Submit</button>
</f-form>
new Vue({
el: '#form_demo',
data: {
message: ''
},
methods: {
showMessage() {
this.$refs.myAlert.success(this.message);
}
}
});
Prop | Type | Required | Default | Description |
---|---|---|---|---|
method | String | false | POST | Form method; GET or POST. |
action | String | false | empty string | Form action. |
ajax | Boolean | false | false | When set to true, prevents default form submission if the form is valid. |
Event | Description |
---|---|
submit | If ajax is set to true, a submit event will be dispatched on submission of a valid form. |
SCSS Variable | Type | Default Value | Description |
---|---|---|---|
$form-field-background-color | Color | transparent | Background color for input and select elements. |
$form-field-color | Color | $global-font-color | Text color for form inputs. |
$form-field-line-height | Number | 1.5 | Line height for form input. |
$form-field-font-size | Number | 16 | Font size for form inputs. |
$form-field-font-family | String | inherit | Font family for form inputs. |
$form-field-font-weight | String | normal | Font weight for form inputs. |
$form-field-border-color | Color | #cacaca | Border color for input and select elements. |
$form-field-border-size | Number | 1px | Border size for input and select elements. |
$form-field-border-style | String | solid | border style for input and select elements. |
$form-field-radius | Number | $global-radius | border radius for input and select elements. |
$form-field-padding | Number | 0.5rem | Padding for input and select elements. |
$form-field-margin | Number | 0 0 $global-margin | Margin for form inputs. |
$form-field-height | Number | 2.4375rem | Height for input and select elements. |
$form-field-width | Number | 100% | Width for input and select elements. |
$form-field-shadow-color | Color | rgba(10, 10, 10, 0.1) | Inner shadow for focused input and select elements. |
The fInput component provides a quick and easy way to add a standardized form input with automatic validation. The fInput directive can generate a textarea or any html5 input type. Validation occurs automatically on blur.
<f-input type="email" label="Email" v-model="email" />
new Vue({
el: '#input_demo',
data: {
email: ''
}
});
Prop | Type | Required | Default | Description |
---|---|---|---|---|
v-model | String | true | Input value. | |
type | String | true | Input type. Will render a textarea if set to textarea. Changing type does not otherwise change the actual input type attribute, but is used for automatic type validation on form submission. | |
label | String | false | empty string | The input label. Label or name will be used in error messaging for invalid inputs on form submission. |
name | String | false | The input name. Label or name will be used in error messaging for invalid inputs on form submission. | |
placeholder | String | false | Input placeholder text. | |
required | Boolean | false | false | If set to true, will invalidate the input if the value is an empty string. |
equal-to | String | false | null | If set, will invalidate the input if it's value does not match the value of equal-to. |
pattern | String | false | null | If set, will invalidate the input if it's value does not match the value of equal-to. |
Renders a checkbox input
checked: {{ checked }}
<f-checkbox v-model="checked" label="My checkbox"></f-checkbox>
new Vue({
el: '#checkbox_demo',
data: {
checked: false
}
});
Prop | Type | Required | Default | Description |
---|---|---|---|---|
v-model | Boolean | true | True if checked; false if not. | |
label | Boolean | true | The checkbox label. | |
required | Boolean | false | false | If true, will invalidate the input if the checkbox is unchecked. |
Renders a radio button input
selected: {{ selectedOption }}
<f-radio label="My Radio Group" v-model="selectedOption" :options="radioOptions" name="myRadioOptions"><f-radio>
new Vue({
el: '#radio_demo',
data: {
selectedOption: '',
radioOptions: [
{ name: 'radioOptionOne', label: 'One Option', value: '1' },
{ name: 'radioOptionTwo', label: 'Two Option', value: '2' }
]
}
});
Prop | Type | Required | Default | Description |
---|---|---|---|---|
v-model | String | true | The selected value. | |
label | String | false | empty string | The label for the radio button group. |
name | String | true | The name for the radio button group. | |
options | Array | true | An array of options to render for the radio group: { name: 'foo', label: 'bar', value: 'baz' } | |
required | Boolean | false | false | If set to true, will invalidate the input if an option is not selected. |
Renders a select input given a set of options
selected: {{ selectedOption }}
<f-select v-model="selectedOption" :options="selectOptions"></f-select>
new Vue({
el: '#select_demo',
data: {
selectedOption: '',
selectOptions: [
{ label: 'One Option', value: '1' },
{ label: 'Two Option', value: '2' },
{ label: 'Red Option', value: 'Red' },
{ label: 'Blue Option', value: 'Blue' }
]
}
});
Prop | Type | Required | Default | Description |
---|---|---|---|---|
v-model | String | true | The selected option value. | |
label | Boolean | false | empty string | The select label. |
options | Array | true | An array of options objects to render: { label: 'foo', value: 'bar' } | |
requires | Boolean | false | false | If set to true, the select will not render an empty option element, and will set the selected option to the first available option. |
You can easy check for required values by attaching the :required="true" to most Forge input components.
Attaching the required attribute to a select element will prevent that element from rendering an empty option as a child of the select.
<f-form :ajax="true" @submit="submit">
<f-input type="text" v-model="input" label="My Input" :required="true"></f-input>
<f-select v-model="selectedOption" :options="selectOptions" :required="true"></f-select>
<f-checkbox v-model="checked" label="My checkbox" :required="true"></f-checkbox>
<f-radio v-model="selectedOption" :options="radioOptions" label="My Radio Group" name="myRadioOptions" :required="true"></f-radio>
<button type="submit" class="button">Submit</button>
</f-form>
new Vue({
el: '#required-validation',
data: {
input: '',
selectedOption: '',
selectOptions: [
{ label: 'One Option', value: '1' },
{ label: 'Two Option', value: '2' },
{ label: 'Red Option', value: 'Red' },
{ label: 'Blue Option', value: 'Blue' }
],
checked: false,
selectedOption: '',
radioOptions: [
{ name: 'radioOptionOne', label: 'One Option', value: '1' },
{ name: 'radioOptionTwo', label: 'Two Option', value: '2' },
]
},
methods: {
submit() {
alert('Form is valid!');
}
}
});
Validating a form field against a particular type is as simple as passing a type attribute to the component. To skip field type validation, set your input type to text.
This is the current list of input types that are automatically validated:
<f-form :ajax="true" @submit="submit">
<f-input type="email" v-model="emailInput" label="Email"></f-input>
<f-input type="url" v-model="urlInput" label="URL"></f-input>
<f-input type="number" v-model="numberInput" label="Number"></f-input>
<f-input type="tel" v-model="telInput" label="Tel"></f-input>
<button type="submit" class="button">Submit</button>
</f-form>
new Vue({
el: '#type-validation',
data: {
emailInput: '',
urlInput: '',
numberInput: '',
telInput: ''
},
methods: {
submit() {
alert('Form is valid!');
}
}
});
To match an input's value against the value of another input, pass the match value into the input via the equal-to attribute.
<f-form :ajax="true" @submit="submit">
<f-input type="text" v-model="passwordInput" label="Password"></f-input>
<f-input type="text" v-model="confirmInput" label="Confirm Password" :equal-to="{ label: 'Password', value: passwordInput }"></f-input>
<button type="submit" class="button">Submit</button>
</f-form>
new Vue({
el: '#match-validation',
data: {
passwordInput: '',
confirmInput: ''
},
methods: {
submit() {
alert('Form is valid!');
}
}
});
ForgeUI is built to customize. The following options giv eyou the ability to modify component templates and/or rename components for maximum flexibility. This allows you to keep the components from this library in sync with your apps style guide without clobbering styles or duplicating code.
Forge.cast(component, template, componentName)
Argument | Type | Required | Description |
---|---|---|---|
component | String | true | The name of the component to cast. |
template | String | false | The new template string to override the default template with. |
componentName | String | false | The alias to use for the component. |
The Forge.cast() method is your primary way of customizing components before registering them to Vue. Use this method to change component templates or to rename components without creating a new component file.
You can customize and rename as many components as you like, up until the point where Vue.use(Forge) is invoked, at which point all unregistered components will be added to Vue.
Forge will register all components that have not been registered to the default component names. For example, is you rename the modal component, and then add Forge to Vue, Forge will still initialize the default modal component to the <modal></modal> component. However, if you change the template of the modal component, Forge will not re-register the same element. This ensures that all the components used by Forge are available, without clobbering any component customizations that have already been registered to Forge.
import Vue from 'vue';
import Forge from 'forge-ui';
// Register a component with a custom template (optional)
import myTemplate from './template.html';
Forge.cast('modal', myTemplate);
// Register a component with a custom name (optional)
Forge.cast('modal', null, 'my-modal'); // you can now use the modal component with <my-modal></my-modal>
// Register all Forge components to Vue
Vue.use(Forge);
Forge comes with a compiled and minified CSS file in the dist folder for prototyping and quick starts. To import the SCSS files as part of your build process, forge comes packages with an extra utility file in the root of the module that will allow you to easily add the appropriate include paths to your Gulp build.
/* gulpfile.js */
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('styles', function () {
return gulp.src('path/to/styles.scss')
.pipe(sass({includePaths: require('forge-ui/includePaths').styles})
.pipe(gulp.dest('dist/css'));
});
For more customization of the styling, each Vue and CSS component comes with a host of SCSS variables that can be configured to taste for each app.
Each variable is declared as a default, so overriding these values is easy. First, though, you'll need to set up your main SCSS file with a settings import and Forge import.
/* /scss/style.css */
@import "_settings";
@import "forge-ui";
/* ... */
At this point, customization is as easy as finding the component in the documentation you wish to modify, and copying the variable name into _settings.scss.
For example, if we want to change the body background color to an off-white color we could add the following to _settings.scss:
/* /scss/_settings.scss */
$body-background: #fefefe;
/* ... */