Commit 63361c5b authored by Nikolay Gromov's avatar Nikolay Gromov

Чекбоксы и радиокнопки

parent d450a30b
...@@ -193,30 +193,78 @@ block content ...@@ -193,30 +193,78 @@ block content
+block-lib('field-text', 'Текстовое поле', false) +block-lib('field-text', 'Текстовое поле', false)
include:markdown-it(linkify html='true' typographer='true' quotes='«»') blocks/field-text/readme.md include:markdown-it(linkify html='true' typographer='true' quotes='«»') blocks/field-text/readme.md
+field-text({ +field-text({
type: 'text',
title: 'Текстовое поле', title: 'Текстовое поле',
placeholder: 'Как заполнять', helpText: 'Подсказка под полем',
helpText: 'Подсказка', isTextarea: true,
}) mods: '',
+field-text({ attrs: {
title: 'Многострочное текстовое поле', name: 'test',
textarea: true, placeholder: 'Подсказка',
placeholder: 'Как заполнять', }
helpText: 'Подсказка',
}) })
+field-text({ +field-text({
type: 'number', title: 'Текстовое поле',
title: 'Текстовое поле (number), ошибочный ввод', helpText: 'Описание ошибки',
placeholder: 'Как заполнять',
helpText: 'Подсказка',
props: 'Подсказка',
mods: 'error', mods: 'error',
inputAttrs: {'id': '200', 'max': '200', 'min': '2'},
}) })
+field-text() +field-text()
+block-lib-code() +block-lib-code()
include:show-code(first-line="//- Pug-файл этого блока:") blocks/field-text/field-text.pug include:show-code(first-line="//- Pug-файл этого блока:") blocks/field-text/field-text.pug
+block-lib('field-checkbox', 'Флажок/чекбокс', false)
include:markdown-it(linkify html='true' typographer='true' quotes='«»') blocks/field-checkbox/readme.md
+field-checkbox([
{
title: 'Чекбокс без группы',
helpText: 'Отдельно расположенный чекбокс',
attrs: {
name: 'check0',
}
},
])
+field-checkbox([
{
title: 'Чекбокс первый',
helpText: 'И, возможно, единственный',
mods: 'error',
attrs: {
name: 'check1',
checked: true,
}
},
{
title: 'Чекбокс второй',
helpText: 'А, нет. Не единственный...',
attrs: {
name: 'check2',
}
},
], 'Общее необязательное название')
+block-lib-code()
include:show-code(first-line="//- Pug-файл этого блока:") blocks/field-checkbox/field-checkbox.pug
+block-lib('field-radio', 'Радиокнопки', false)
include:markdown-it(linkify html='true' typographer='true' quotes='«»') blocks/field-radio/readme.md
+field-radio([
{
title: 'Первый',
helpText: 'И, возможно, единственный',
attrs: {
name: 'radio',
checked: true,
}
},
{
title: 'Второй',
helpText: 'А, нет. Не единственный...',
attrs: {
name: 'radio',
}
},
], 'Общее необязательное название')
+block-lib-code()
include:show-code(first-line="//- Pug-файл этого блока:") blocks/field-radio/field-radio.pug
.burger.blocks-library__menu-toggler(data-toggle="off-canvas") .burger.blocks-library__menu-toggler(data-toggle="off-canvas")
......
...@@ -6,14 +6,14 @@ mixin alert(title, mods) ...@@ -6,14 +6,14 @@ mixin alert(title, mods)
//- title {string} - заголовок //- title {string} - заголовок
//- mods {string} - стилевые модификаторы //- mods {string} - стилевые модификаторы
//- Вызов: //- Вызов:
//- +alert() +alert()
//- p Успех p Успех
//- +alert('Внимание!', 'warning, some-mod-name') +alert('Внимание!', 'warning, some-mod-name')
//- p Текст p Текст
//- +alert() +alert()
//- p Сообщение без модификаторов p Сообщение без модификаторов
//- +alert('Заголовok', 'danger') +alert('Заголовok', 'danger')
//- p Проблема p Проблема
- -
//- список модификаторов //- список модификаторов
......
...@@ -7,9 +7,9 @@ mixin btn(text, mods, isInput) ...@@ -7,9 +7,9 @@ mixin btn(text, mods, isInput)
//- mods {string} - список модификаторов //- mods {string} - список модификаторов
//- isInput {bool} - флаг «это тег input» //- isInput {bool} - флаг «это тег input»
//- Вызов: //- Вызов:
//- +btn('Кнопка-ссылка')(href='/') - есть href, это точно ссылка +btn('Кнопка-ссылка')(href='/') - есть href, это точно ссылка
//- +btn('Кнопка-input', '', true) - есть флаг isInput, это input +btn('Кнопка-input', '', true) - есть флаг isInput, это input
//- +btn('Кнопка-button', 'success') - нет href, нет isInput — это button +btn('Кнопка-button', 'success') - нет href, нет isInput — это button
- -
// список модификаторов // список модификаторов
......
//- Все примеси в этом файле должны начинаться c имени блока (burger) //- Все примеси в этом файле должны начинаться c имени блока (burger)
mixin burger(label, targetId, className) mixin burger(label, targetId, switchableClass)
//- Принимает: //- Принимает:
//- label {string} - описание, значение атрибута aria-label //- label {string} - описание, значение атрибута aria-label
//- targetId {string} - атрибут id целевого элемента (без символа #), на котором по клику будет меняться класс //- targetId {string} - атрибут id целевого элемента (без символа #), на котором по клику будет меняться класс
//- className {string} - класс, добавляемый/убираемый с целевого элемента //- switchableClass {string} - класс, добавляемый/убираемый с целевого элемента
//- Вызов: //- Вызов:
//- +burger('Показать пример кода', 'burger-code', 'blocks-library__code--shown') +burger('Показать пример кода', 'burger-code', 'blocks-library__code--shown')
//- +burger('Показать ничто')(data-some="SOME") +burger('Показать ничто')(data-some="SOME")
- -
label = label || 'Toggle block ' + targetId label = label || 'Toggle block ' + targetId
if (typeof(targetId) !== 'undefined' && targetId !== '') attributes['data-target-id'] = targetId if (typeof(targetId) !== 'undefined' && targetId !== '') attributes['data-target-id'] = targetId
if (typeof(className) !== 'undefined' && className !== '') attributes['data-target-class-toggle'] = className if (typeof(switchableClass) !== 'undefined' && switchableClass !== '') attributes['data-target-class-toggle'] = switchableClass
button.burger(aria-label=label)&attributes(attributes) button.burger(aria-label=label)&attributes(attributes)
span= label span= label
...@@ -5,7 +5,7 @@ mixin close(label) ...@@ -5,7 +5,7 @@ mixin close(label)
//- Принимает: //- Принимает:
//- label {string} - описание, значение атрибута aria-label //- label {string} - описание, значение атрибута aria-label
//- Вызов: //- Вызов:
//- +close('Закрыть') +close('Закрыть')
button.close(aria-label=label)&attributes(attributes) button.close(aria-label=label)&attributes(attributes)
span= label span= label
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
mixin code() mixin code()
//- Вызов: //- Вызов:
//- +code() +code()
//- code <div class="some">...</div> code <div class="some">...</div>
//- code <div class="some">...</div> code <div class="some">...</div>
pre.code&attributes(attributes) pre.code&attributes(attributes)
block block
<!--DEV
Для использования этого файла как шаблона:
@ @include('blocks/field-checkbox/field-checkbox.html')
(Нужно убрать пробел между символами @)
Подробнее: https://www.npmjs.com/package/gulp-file-include
<div class="field-checkbox">
<label class="field-checkbox__name">
<input class="field-checkbox__input" type="checkbox" id="" name="" checked>
<span class="field-checkbox__name-text">Текст у флажка</span>
</label>
</div>
<div class="field-checkbox">
<div class="field-checkbox__title">Необязательный общий заголовок</div>
<div class="field-checkbox__input-wrap">
<label class="field-checkbox__name">
<input class="field-checkbox__input" type="checkbox" id="" name="" checked>
<span class="field-checkbox__name-text">Текст у флажка</span>
</label>
<div class="field-checkbox__help-text-wrap">
<div class="field-checkbox__help-text">Пояснение</div>
</div>
</div>
<div class="field-checkbox__input-wrap">
<label class="field-checkbox__name">
<input class="field-checkbox__input" type="checkbox" id="" name="">
<span class="field-checkbox__name-text">Текст у флажка</span>
</label>
</div>
<div class="field-checkbox__input-wrap">
<label class="field-checkbox__name">
<input class="field-checkbox__input" type="checkbox" id="" name="">
<span class="field-checkbox__name-text">Текст у флажка</span>
</label>
</div>
</div>
-->
//- Все примеси в этом файле должны начинаться c имени блока (field-checkbox)
mixin field-checkbox(checkboxes, title)
//- Принимает:
//- checkboxes {array}
//- {
//- title: '' {string} - текст рядом с чекбоксом
//- helpText: '' {string} - пояснение под полем
//- mods: '' {string} - модификаторы блока
//- attrs: { {object} - любые атрибуты для input
//- type: {string}
//- placeholder: {string}
//- ...
//- }
//- },
//- ...
//- Вызов:
+field-checkbox([
{
title: 'Чекбокс0',
helpText: 'Подсказка',
attrs: {
name: 'check0',
}
},
])
+field-checkbox([
{
title: 'Чекбокс1',
helpText: 'Подсказка',
mods: 'error',
attrs: {
name: 'check1',
checked: true,
}
},
{
title: 'Чекбокс2',
helpText: 'Подсказка',
mods: 'error',
attrs: {
name: 'check2',
}
},
], 'ОбщееНазваниеБлока')
.field-checkbox&attributes(attributes)
if(typeof(title) !== 'undefined' && title)
.field-checkbox__title!= title
each checkbox in checkboxes
-
var allMods = '';
if(typeof(checkbox.mods) !== 'undefined' && checkbox.mods) {
var modsList = checkbox.mods.split(',');
for (var i = 0; i < modsList.length; i++) {
allMods = allMods + ' field-checkbox__input-wrap--' + modsList[i].trim();
}
}
.field-checkbox__input-wrap(class=allMods)
label.field-checkbox__name
input.field-checkbox__input(type='checkbox')&attributes(checkbox.attrs)
span.field-checkbox__name-text!= checkbox.title
if(typeof(checkbox.helpText) !== 'undefined' && checkbox.helpText)
.field-checkbox__help-text-wrap
.field-checkbox__help-text!= checkbox.helpText
...@@ -83,6 +83,7 @@ $line-height: 1.375em !default; ...@@ -83,6 +83,7 @@ $line-height: 1.375em !default;
border-bottom: 2px solid currentColor; border-bottom: 2px solid currentColor;
transform: rotate(-45deg); transform: rotate(-45deg);
transition: opacity $transition-time; transition: opacity $transition-time;
box-shadow: 1px 2px 0 #fff, inset 0 -2px 0 #fff;
@at-root input:checked ~ & { @at-root input:checked ~ & {
opacity: 1; opacity: 1;
......
В стилевом файле есть закомментированные фрагменты для замены нативного элемента своим (svg).
<!--DEV
Для использования этого файла как шаблона:
@ @include('blocks/field-radio/field-radio.html')
(Нужно убрать пробел между символами @)
Подробнее: https://www.npmjs.com/package/gulp-file-include
<div class="field-radio">
<label class="field-radio__name">
<input class="field-radio__input" type="radio" id="" checked>
<span class="field-radio__name-text">Текст у радиобаттона</span>
</label>
</div>
<div class="field-radio">
<div class="field-radio__title">Необязательный общий заголовок</div>
<div class="field-radio__input-wrap">
<label class="field-radio__name">
<input class="field-radio__input" type="radio" id="" name="demo-radio" checked>
<span class="field-radio__name-text">Текст у радиобаттона</span>
</label>
<div class="field-radio__help-text-wrap">
<div class="field-radio__help-text">Пояснение.</div>
</div>
</div>
<div class="field-radio__input-wrap">
<label class="field-radio__name">
<input class="field-radio__input" type="radio" id="" name="demo-radio">
<span class="field-radio__name-text">Текст у радиобаттона</span>
</label>
</div>
<div class="field-radio__input-wrap">
<label class="field-radio__name">
<input class="field-radio__input" type="radio" id="" name="demo-radio">
<span class="field-radio__name-text">Текст у радиобаттона</span>
</label>
</div>
</div>
-->
//- Все примеси в этом файле должны начинаться c имени блока (field-radio)
mixin field-radio(radiobuttons, title)
//- Принимает:
//- radiobuttons {array}
//- {
//- title: '' {string} - текст рядом с чекбоксом
//- helpText: '' {string} - пояснение под полем
//- mods: '' {string} - модификаторы блока
//- attrs: { {object} - любые атрибуты для input
//- type: {string}
//- placeholder: {string}
//- ...
//- }
//- },
//- ...
//- Вызов:
+field-radio([
{
title: 'Радиокнопка1',
helpText: 'Подсказка',
mods: '',
attrs: {
name: 'radio',
checked: true,
}
},
{
title: 'Радиокнопка2',
helpText: 'Подсказка',
mods: '',
attrs: {
name: 'radio',
}
},
], 'ОбщееНазваниеБлока')
.field-radio&attributes(attributes)
if(typeof(title) !== 'undefined' && title)
.field-radio__title!= title
each checkbox in radiobuttons
-
var allMods = '';
if(typeof(checkbox.mods) !== 'undefined' && checkbox.mods) {
var modsList = checkbox.mods.split(',');
for (var i = 0; i < modsList.length; i++) {
allMods = allMods + ' field-radio__input-wrap--' + modsList[i].trim();
}
}
.field-radio__input-wrap(class=allMods)
label.field-radio__name
input.field-radio__input(type='radio')&attributes(checkbox.attrs)
span.field-radio__name-text!= checkbox.title
if(typeof(checkbox.helpText) !== 'undefined' && checkbox.helpText)
.field-radio__help-text-wrap
.field-radio__help-text!= checkbox.helpText
В стилевом файле есть закомментированные фрагменты для замены нативного элемента своим (svg).
...@@ -5,25 +5,25 @@ mixin field-text(props) ...@@ -5,25 +5,25 @@ mixin field-text(props)
//- Принимает: //- Принимает:
//- props { //- props {
//- title: '' {string} - текст с названием (выводится над полем) //- title: '' {string} - текст с названием (выводится над полем)
//- type: '' {string} - тип для input [text|email|number...] //- isTextarea: false {bool} - флаг input/textarea
//- placeholder: '' {string} - подсказка в поле
//- name: '' {string} - атрибут name у input/textarea
//- inputAttrs: {} {object} - дополнительные атрибуты для input/textarea
//- mods: '' {string} - модификаторы блока
//- textarea: false {bool} - флаг input/textarea
//- helpText: '' {string} - пояснение под полем //- helpText: '' {string} - пояснение под полем
//- mods: '' {string} - модификаторы блока
//- attrs: { {object} - любые атрибуты для input/textarea
//- type: {string}
//- placeholder: {string}
//- ...
//- }
//- } //- }
//- Вызов: //- Вызов:
//- +field-text({ +field-text({
//- title: 'Текст', title: 'Название',
//- type: 'text', isTextarea: true,
//- placeholder: '', helpText: 'Подсказка',
//- name: '', mods: '',
//- inputAttrs: {'id': 'some-input-id', 'max': '200', 'min': '2'}, attrs: {
//- mods: '', name: 'comment',
//- textarea: false, }
//- helpText: '', })
//- })
- -
if(typeof(props) === 'undefined') { if(typeof(props) === 'undefined') {
...@@ -41,17 +41,13 @@ mixin field-text(props) ...@@ -41,17 +41,13 @@ mixin field-text(props)
if(typeof(props.title) !== 'undefined' && props.title) if(typeof(props.title) !== 'undefined' && props.title)
span.field-text__name!= props.title span.field-text__name!= props.title
span.field-text__input-wrap span.field-text__input-wrap
if(typeof(props.textarea) !== 'undefined' && props.textarea) if(typeof(props.isTextarea) !== 'undefined' && props.isTextarea)
textarea.field-text__input( textarea.field-text__input(
placeholder=props.placeholder ? props.placeholder : '' )&attributes(props.attrs)
name=props.name ? props.name : ''
)&attributes(props.inputAttrs)
else else
input.field-text__input( input.field-text__input(
type=props.type ? props.type : 'text' type=(typeof(props.attrs) !== 'undefined' && props.attrs.type) ? props.attrs.type : 'text'
placeholder=props.placeholder ? props.placeholder : '' )&attributes(props.attrs)
name=props.name ? props.name : ''
)&attributes(props.inputAttrs)
if(typeof(props.helpText) !== 'undefined' && props.helpText) if(typeof(props.helpText) !== 'undefined' && props.helpText)
span.field-text__help-text!= props.helpText span.field-text__help-text!= props.helpText
block block
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
mixin main-nav(selectedID) mixin main-nav(selectedID)
//- Принимает: //- Принимает:
//- selectedID {string} - id пункта меню, указанное в main-nav.json //- selectedID {string} - id пункта меню ( по умолчанию — из main-nav.json)
//- Вызов: //- Вызов:
//- +main-nav('1') +main-nav('1')
nav.main-nav#nav&attributes(attributes) nav.main-nav#nav&attributes(attributes)
+burger('Показать главное меню', 'nav', 'main-nav--open')(class="main-nav__toggler") +burger('Показать главное меню', 'nav', 'main-nav--open')(class="main-nav__toggler")
......
По умолчанию данные меню берутся из `main-nav/main-nav.json` и передаются в компилятор pug (см. `gulpfile.js`).
По получению ссылками фокуса на их родителей с `.main-nav__item` добавляется модификатор `.main-nav__item--show-child`, что позволяет работать со вложенными меню с клавиатуры (предусмотрено 3 уровня). По получению ссылками фокуса на их родителей с `.main-nav__item` добавляется модификатор `.main-nav__item--show-child`, что позволяет работать со вложенными меню с клавиатуры (предусмотрено 3 уровня).
На малых ширинах преобразуется в мобильный вид, скрывается/показывается по клику на бургер, если JS включен (на `html` есть класс `js`). На малых ширинах преобразуется в мобильный вид, скрывается/показывается по клику на бургер, если JS включен (на `html` есть класс `js`).
...@@ -5,19 +5,19 @@ mixin menu(menu) ...@@ -5,19 +5,19 @@ mixin menu(menu)
//- Принимает: //- Принимает:
//- menu {array} - массив с пунктами меню //- menu {array} - массив с пунктами меню
//- Вызов: //- Вызов:
//- - -
//- var myMenu = [ var myMenu = [
//- { {
//- 'text':'Пункт1', 'text':'Пункт1',
//- 'url':'/', 'url':'/',
//- }, },
//- { {
//- 'text':'Пункт2', 'text':'Пункт2',
//- 'url':'/', 'url':'/',
//- 'mods': 'separator, active', 'mods': 'separator, active',
//- }, },
//- ]; ];
//- +menu(myMenu) +menu(myMenu)
- -
if (typeof(menu) === 'undefined') { if (typeof(menu) === 'undefined') {
......
...@@ -8,8 +8,8 @@ mixin thumb(url, alt, width, height) ...@@ -8,8 +8,8 @@ mixin thumb(url, alt, width, height)
//- width {string} - соотв. атрибут тега картинки //- width {string} - соотв. атрибут тега картинки
//- height {string} - соотв. атрибут тега картинки //- height {string} - соотв. атрибут тега картинки
//- Вызов: //- Вызов:
//- +thumb('img/joker.jpg', 'Джокер', 300, 200) +thumb('img/joker.jpg', 'Джокер', 300, 200)
//- +thumb('img/joker.jpg', 'Джокер', 300) +thumb('img/joker.jpg', 'Джокер', 300)
- if (typeof(url) !== 'undefined') - if (typeof(url) !== 'undefined')
img.thumb(src=url, alt=alt, width=width, height=height)&attributes(attributes) img.thumb(src=url, alt=alt, width=width, height=height)&attributes(attributes)
......
...@@ -9,3 +9,5 @@ include ../blocks/alert/alert.pug ...@@ -9,3 +9,5 @@ include ../blocks/alert/alert.pug
include ../blocks/menu/menu.pug include ../blocks/menu/menu.pug
include ../blocks/btn/btn.pug include ../blocks/btn/btn.pug
include ../blocks/field-text/field-text.pug include ../blocks/field-text/field-text.pug
include ../blocks/field-checkbox/field-checkbox.pug
include ../blocks/field-radio/field-radio.pug
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment