0.1.0-alpha.13 • Published 4 years ago

@guyn-style/forms v0.1.0-alpha.13

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

Forms

<div class="html-example">
	<form>
		<h4>Basic information</h4>
		<div class="input-text">
			<input type="text" />
			<label>Name</label>
		</div>
		<div class="input-text">
			<input type="email" />
			<label>E-mail</label>
		</div>
		<div class="input-text">
			<input type="email" />
			<label>E-mail</label>
		</div>
		<h4>Do you like this?</h4>
		<div class="input-switch">
			<input type="checkbox" id="input-switch-test1" />
			<label for="input-switch-test1">Yeah</label>
		</div>
		<h4>What grade would you give this form?</h4>
		<div class="input-range">
			<input type="range" min="0" max="50" />
			<label>With min/max</label>
		</div>
		<h4>Yes?</h4>
		<div class="input-checkbox">
			<input type="checkbox" id="input-check-test1" />
			<label for="input-check-test1">Sure!</label>
		</div>
		<h4>More?</h4>
		<div class="input-radio">
			<input type="radio" name="radio1" id="input-radio-test1" />
			<label for="input-radio-test1">Yes</label>
		</div>
		<div class="input-radio">
			<input type="radio" name="radio1" id="input-radio-test2" />
			<label for="input-radio-test2">No</label>
		</div>
	</form>
</div>

Checkbox & Radio

The Checkbox and radio inputs are quite similar, thats why you can style them in the same matter.

Code Example

<div class="input-checkbox-element">
	<input id="my-checkbox" type="checkbox" />
	<label for="my-checkbox">Should this be checked?</label>
</div>

Make sure you have a wrapper and an input with directly after that the label.

.input-checkbox-element {
	@include input-checkbox();
}

Styling

ElementPropertySass VariableCustom PropertyDefault value
Overall
box-shadow$input-form-shadow--input-form-shadow0 0 1rem 0 rgba(0, 0, 0, 0)
:focus box-shadow$input-form-shadow-focus--input-form-shadow-focus0 0 1rem 0 rgba(0, 0, 0, 0.05)
transition$input-form-transition--input-form-transition.3s ease-in-out
Label
border-radius$input-form-label-border-radius--input-form-label-border-radius0px
color$input-form-label-text-color--input-form-label-text-colorcurrentColor
line-height$input-form-label-line-height--input-form-label-border-radius0px
transition$input-form-label-transition--input-form-label-transitioninherit $input-form-transition
padding$input-form-label-padding--input-form-label-padding1rem
padding-left$input-form-label-padding-left--input-form-label-padding-leftcalc(#{$input-form-body-width} + #{$input-form-label-padding} + #{$input-form-body-left})
Radio/Checkbox Body
top$input-form-body-top--input-form-body-topinherit $input-form-label-padding
left$input-form-body-left--input-form-body-left#{$input-form-label-padding
width$input-form-body-width--input-form-body-width1rem
height$input-form-body-height--input-form-body-height1rem
border$input-form-body-border--input-form-body-border1px solid currentColor
background$input-form-body-background--input-form-body-backgroundwhite
box-shadow$input-form-body-shadow--input-form-body-shadowinherit $input-form-shadow
transition$input-form-body-transition--input-form-body-transitioninherit $input-form-transition
border-radius$input-form-body-border-radius--input-form-body-border-radius2px
Radio/Checkbox check
border-radius$input-form-check-border-radius--input-checkbox-body-border-radiusinherit $input-form-body-border-radius
top$input-form-check-top--input-form-check-topcalc(#{$input-form-label-padding} + ($input-form-body-height / 2 - $input-form-check-height / 2))
left$input-form-check-left--input-form-check-leftcalc(#{$input-form-label-padding} + ($input-form-body-width / 2 - $input-form-check-width / 2))
width$input-form-check-width--input-form-check-width0.5rem
height$input-form-check-height--input-form-check-height0.5rem
border$input-form-check-border--input-form-check-border0
background$input-form-check-background--input-form-check-backgroundcurrentcolor
transition$input-form-check-transition--input-form-check-transitioninherit $input-form-transition
border-radius$input-form-check-border-radius--input-form-check-border-radius0
Radio
border-radius$input-radio-body-border-radius--input-radio-body-border-radius50%
border-radius$input-radio-check-border-radius--input-radio-check-border-radius50%

Mixins

There are several mixins to target different parts of an element.

MixinTargetsArgument
input-form-bodyBody element of the clickable input.\$type - checkbox or radio
input-form-body-checkedChecked - Body element of the clickable input.\$type - checkbox or radio
input-form-checkCheck element of the clickable input.\$type - checkbox or radio
input-form-check-checkedChecked - Check element of the clickable input.\$type - checkbox or radio
input-form-labelFull label of the html, before and after are used for the input.\$type - checkbox or radio
input-form-label-checkedChecked - Full label of the html, before and after are used for the input.\$type - checkbox or radio
input-form-label-hoverHovered - Full label of the html, before and after are used for the input.\$type - checkbox or radio
input-form-label-focusFocused - Full label of the html, before and after are used for the input.\$type - checkbox or radio
input-form-inputInput element of the html, this element will be hidden.\$type - checkbox or radio
input-radio-bodyBody element of the clickable input.
input-radio-body-checkedChecked - Body element of the clickable radio input.
input-radio-checkCheck element of the clickable radio input.
input-radio-check-checkedChecked - Check element of the clickable radio input.
input-radio-labelFull label of the html, before and after are used for the radio input.
input-radio-label-checkedChecked - Full label of the html, before and after are used for the radio input.
input-radio-label-hoverHovered - Full label of the html, before and after are used for the radio input.
input-radio-label-focusFocused - Full label of the html, before and after are used for the radio input.
input-radio-inputRadio Input element of the html, this element will be hidden.
input-checkbox-bodyBody element of the clickable input.
input-checkbox-body-checkedChecked - Body element of the clickable checkbox input.
input-checkbox-checkCheck element of the clickable checkbox input.
input-checkbox-check-checkedChecked - Check element of the clickable checkbox input.
input-checkbox-labelFull label of the html, before and after are used for the checkbox input.
input-checkbox-label-checkedChecked - Full label of the html, before and after are used for the checkbox input.
input-checkbox-label-hoverHovered - Full label of the html, before and after are used for the checkbox input.
input-checkbox-label-focusFocused - Full label of the html, before and after are used for the checkbox input.
input-checkbox-inputCheckbox Input element of the html, this element will be hidden.

Input Range

The range slider is a quite hard to style element. With the mixin this will be a lot easier and it will keep it all its normal behaviour.

Mixins

input-range-container

Create all elements for a container of the range slider with its defaults.

.element {
	@include input-range-container();
}

input-range

Default include for range slider, all range sliders within element will be styled.

<div class="input-range">
	<input type="range" min="0" max="100" id="my-range-slider" />
	<label for="my-range-slider">My range slider</label>
</div>
.element {
	@include input-range();
}

Or give a class or the range slider, in this way the mixins can be used anywhere but will only target the specific range slider with given class.

@include input-range(".my-range-slider");

input-range-input

Only targets the input of the range slider

.element {
	@include input-range();
}

input-range-input

Targets the label which comes after the Range slider

.element {
	@include input-range();
}

input-range-track

If there are any property which you want to set on the track only, you can use the input-range-track mixin.

@include input-range-track {
	opacity: 0.5;
	&:hover {
		background-color: red;
	}
}

input-range-thumb

If there are any property which you want to set on the track only, you can use the input-range-thumb mixin.

@include input-range-thumb {
	&:hover {
		transform: scale(1.2);
	}
}

Styling the Range slider

There is some default styling which can easily be overwritten. This can be done using CSS custom properties or defining sass variables before you use the mixin.

ElementPropertySass VariableCustom PropertyDefault value
Range Slider
width$input-range-width--input-range-width100%
height$input-range-height--input-range-height1rem
shadow$input-range-shadow--input-range-shadow1px 1px 3px rgba(black, 0.2) inset
border$input-range-border--input-range-border0
border-radius$input-range-border-radius--input-range-border-radius50%
background$input-range-background--input-range-backgroundtransparent
Thumb
width$input-range-thumb-width--input-range-thumb-width1rem
height$input-range-thumb-height--input-range-thumb-height1rem
shadow$input-range-thumb-shadow--input-range-thumb-shadowinherit: range-shadow
border$input-range-thumb-border--input-range-thumb-border0
border-radius$input-range-thumb-border-radius--input-range-thumb-border-radius50%
background$input-range-thumb-background--input-range-thumb-backgroundblue
Track
width$input-range-track-width--input-range-widthauto
height$input-range-track-height--input-range-height0.5rem
shadow$input-range-track-shadow--input-range-track-shadowinherit: range-shadow
border$input-range-track-border--input-range-thumb-border0
border-radius$input-range-track-border-radius--input-range-thumb-border-radius50%
background$input-range-track-background--input-range-thumb-backgroundwhite
Min Max
$input-range-max-label-padding0.5em
$input-range-max-label-left100%
$input-range-max-label-top50%
$input-range-max-label-transformtranslateY(-50%)
$input-range-min-label-padding0.5em
$input-range-min-label-right100%
$input-range-min-label-top50%
$input-range-min-label-transformtranslateY(-50%)
Settings
$input-range-container-reversetrue
$input-range-min-labeltrue
$input-range-max-labeltrue

Switch

Just a simple yes or no on a field can be done with a switch

<div class="input-switch">
	<input type="checkbox" id="input-switch-test1" />
	<label for="input-switch-test1">Yeah</label>
</div>
body {
	@include input-switch-container(".input-switch");
}

Styling variables

ElementPropertySass VariableCustom PropertyDefault value
Label
$input-switch-label-padding--input-switch-label-padding1em
Body
$input-switch-body-width--input-switch-body-width1.5rem
$input-switch-body-height--input-switch-body-height1rem
$input-switch-body-border-radius--input-switch-body-heightcalc(#{$input-switch-body-height} / 2)
$input-switch-body-background--input-switch-body-backgroundwhite
$input-switch-body-border--input-switch-body-border1px solid currentColor
$input-switch-check-width--input-switch-check-width.5rem
Check
$input-switch-check-height--input-switch-check-height.5rem
$input-switch-check-border-radius--input-switch-check-heightcalc(#{$input-switch-check-height} / 2)
$input-switch-check-top--input-switch-check-topcalc(50% - (#{$input-switch-check-height} / 2))
$input-switch-check-background--input-switch-check-backgroundblack
$input-switch-check-border--input-switch-check-border0
$input-switch-check-shadow--input-switch-check-shadow0 0 0 2px black inset

Input Text

Styling input fields can be a pain, but Guyn makes it a little easier without losing all control. The only thing necessary is just to keep up with a simple buildup.

Simple Example

<section class="my-section">
	...
	<div class="input-text">
		<input type="text" id="my-input" placeholder="John Doe" />
		<label>Name</label>
	</div>
	...
</section>
.my-section {
	@include input-text-container(".input-text");
}

You don't have to be "unlogically" turning the input and the label around, but in order to give your field some extra interaction, this is necessary. If you don't you will just loose that. Just make sure to "unreverse" the container with $input-text-container-reverse: false; before the include.

Types

By default the mixin gives you the following types for inputs; email, tel, number, search, url, password, date, datetime-local, month, time and text. This can be adjusted by passing just the type you want, or a list of types to any of the mixins.

.my-section{
	// Target only input[type="text"]
	@include input-text-container('.input-container', 'text');

	// Target both input[type="text"] and input[type="email"]
	@include input-text-container('.input-container', ('text','email'));

	// Target all
	@include input-text-container('.input-container'));
}

Mixins

There is a whole set of mixins to style your elements.

MixinTargetDescriptionArguments
input-textinputCreate all default styling on the input + label[$types]
input-text-containerparentAdds the input text automatically[$class, $types]
input-text-labelinput + labelTargets just the lable[$types]
input-text-focusinput:focusTargets a focussed input[$types]
input-text-label-focusinput:focus + labelTargets the label when the input is focussed[$types]
input-text-placeholderinput:placeholderTargets the placeholder of an input[$types]
input-text-placeholder-showninput:placeholder-shownTargets the input when the placeholder is shown[$types]
input-text-label-filledinput:placeholder-shown + labelTargets the label when the placeholder is shown (input is empty)[$types]

Styling Variables

ElementPropertySass VariableCustom PropertyDefault value
Input
width$input-text-input-widthinput-text-input-width100%
box-shadow$input-text-input-shadowinput-text-input-shadow0 0 1rem 0 rgba(0,0,0,0)
focus: box-shadow$input-text-input-focus-shadowinput-text-input-shadow0 0 1rem 0 rgba(0,0,0,0.25)
border$input-text-input-borderinput-text-input-border1px solid currentColor
background$input-text-input-backgroundinput-text-input-backgroundtransparent
color$input-text-input-colorinput-text-input-colorcurrentColor
font-size$input-text-input-font-sizeinput-text-input-font-size1em
font-family$input-text-input-font-familyinput-text-input-font-familyinherit
padding$input-text-input-paddinginput-text-input-padding1em
opacity$input-text-input-opacityinput-text-input-opacity1
transition$input-text-input-transitioninput-text-input-transition0.3s ease-in-out
Label
width$input-text-label-widthinput-text-label-width100%
box-shadow$input-text-label-shadowinput-text-label-shadow0 0 1rem 0 rgba(0,0,0,0)
border$input-text-label-borderinput-text-label-border0
background$input-text-label-backgroundinput-text-label-backgroundtransparent
color$input-text-label-colorinput-text-label-colorcurrentColor
font-size$input-text-label-font-sizeinput-text-label-font-size1em
font-family$input-text-label-font-familyinput-text-label-font-familyinherit
padding$input-text-label-paddinginput-text-label-padding1em
opacity$input-text-label-opacityinput-text-label-opacity0.75
transition$input-text-label-transitioninput-text-label-transition0.3s ease-in-out
focus: opacity$input-text-label-focus-opacityinput-text-label-focus-opacity1
filled: opacity$input-text-label-filled-opacityinput-text-label-filled-opacity1
Input Placeholder
focus: opacity$input-text-placeholder-focus-opacityinput-text-placeholder-focus-opacity0.5
Container
position$input-text-container-positioninput-text-container-position100%
width$input-text-container-widthinput-text-container-width100%
$input-text-container-reversetrue
margin$input-text-container-margininput-text-container-margin1em