diff --git a/README.md b/README.md index 3651023ab..ee2db4e20 100644 --- a/README.md +++ b/README.md @@ -309,7 +309,7 @@ Each test consists of a pair of files implemented in following technologies: BEM For each block: * BEMJSON file contains an example for a block; -* HTML file contains standard HTML code – a block sample. +* HTML file contains standard HTML code – a block sample. Block sample in HTML is a block implementation result that becomes available after applying a template to the BEMJSON example. diff --git a/common.blocks/button/button.en.md b/common.blocks/button/button.en.md index 5b6d285e5..87f8b19cc 100644 --- a/common.blocks/button/button.en.md +++ b/common.blocks/button/button.en.md @@ -1,305 +1,446 @@ # button -`button` block is used to manage size, state, content and appearance of a button. - -## Custom fields of a block - -The following custom fields could be specified in BEMJSON declaration of the block: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Custom field nameTypeDescription
text - String - Text of a button. Specifies text HTML attribute to a button.
icon - BEMJSON - Button with an icon realized by icon block.
url - String - URL address. It is used only for a button with link behavior. -
Specifies href HTML attribute to a button.
id - String - Unique identifier of a button. -

Specifies id HTML attribute to a button.
tabIndex - String - Defines tab order between the buttons.
value - String - Specifies value that will be sent to a server or obtained using client scripts. It is empty by default. Pair id=val is sent to a server, where id is set by id attribute and value – by val attribute.
- -Additional required HTML attributes could be specified in `attrs` field of BEMJSON. - -## Modifiers of a block - -### _theme - -Block supports the following themes: - - * simple - * islands (**NB!** Choosing a theme `islands` requires additional modifier [`size`](#size).) - -If `theme` modifier is not specified, [native](#native) representation of a control is applied. - -See following examples: - - -**default** - -```bemjson +A block is used to create different types of buttons. + +## Brief overview + +### Modifiers of the block + +| Modifier | Available values | Use cases | Description | +| ----------- | ------------------- | -------------------- | -------- | +| type | 'link', 'submit' | BEMJSON | A button type.| +| togglable | 'check', 'radio' | BEMJSON | A toggle type of a button.| +| disabled | true | BEMJSON, JS | A disabled state. | +| focused | true | BEMJSON, JS | The block is in focus. | +| pressed | true | – | A pressed state. | +| hovered | true | – | A hovered state. | +| theme | 'islands' | BEMJSON | A custom design. | +| size | 's', 'm', 'l', 'xl' | BEMJSON | A button size. Use sizes only for buttons with theme modifier with islands value.| +| view | 'action', 'pseudo' | BEMJSON | Visual highlighting.| + +### Custom fields of the block + +| Field | Type | description | +| ---- | --- | -------- | +| name | String | A unique block name. Do not use for type modifier with link value. | +| val | String | A value that will be sent to a server. Do not use for type modifier with link value. | +| text | String| A button text. | +| url | String| A link address. Use only for type modifier with link value. | +| icon | BEMJSON | An icon on a button that is formed by icon block. | +| title | String | A tooltip content. | +| id | BEMJSON | A unique identifier of a button. | +| tabIndex | Number | A sequence that user follows when he uses the `Tab` key to navigate through a page. | + +## Block overview + +`button` block is used to manage a size, state, and appearance of a button. + +### Modifiers of the block + + + +#### `type` modifier + +Available values: `'link'`, `'submit'`. + +Use case: `BEMJSON`. + + + +##### A link-button (`type` modifier with `link` value) + +Use `type` modifier with `link` value to create a button that opens a page by an address specified in url field. + +```js { block : 'button', - text : 'No theme' + mods : { theme : 'islands', size : 'm', type : 'link' }, + url : 'https://bem.info/', + text : 'Try BEM' } ``` -**simple** +##### A form submit button (`type` modifier with `submit` value) -```bemjson +Use `type` modifier with `submit` value to create a button that sends data to a server. This button type must be a part of a form. + +```js { block : 'button', - text : 'Theme simple', - mods : { theme : 'simple' } + mods : { theme : 'islands', size : 'm', type : 'submit' }, + text : 'Send data' } ``` -**islands** + + +#### `togglable` modifier + +Available values: `'check'`, `'radio'`. + +Use case: `BEMJSON`. + +Defines behavior of a pressed button. -```bemjson +##### A toggle button (`togglable` modifier with `check` value) + +The first click presses the button, and the second one releases it. + +```js { block : 'button', - text : 'Theme islands', - mods : { theme : 'islands', size : 'm' } + mods : { theme : 'islands', size : 'm', togglable : 'check' }, + text : 'I am pressed' } ``` - -### _size +##### A radio-button (`togglable` modifier with `radio` value) -Implemented only for theme `islands`. +The first click presses the button, and it cannot be released manually. +This button type is used as a part of [radio-group](../radio-group/radio-group.en.md). -Provides all types of buttons with `size` value. +```js +{ + block : 'button', + mods : { theme : 'islands', size : 'm', togglable : 'radio' }, + text : 'I am toggled' +} +``` + +An example of the button usage as a part of the radio-group: -There are four sizes available: **s**, **m**, **l**, **xl**. - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SizeFont sizeButton height
s13px24px
m13px28px
l15px32px
xl18px38px
- -See following examples: - -```bemjson +```js +{ + block : 'radio-group', + mods : { theme : 'islands', size : 'm', type : 'button', togglable : 'radio' }, + name : 'radio-button', + val : 2, + options : [ + { val : 1, text : 'First' }, + { val : 2, text : 'Second' }, + { val : 3, text : 'Third' } + ] +} +``` + + + +#### `disabled` modifier + +Available value: `true`. + +Use case: `BEMJSON`, `JS`. + +The modifier provides inactive state to the block. Disabled block is visible but not available for user actions. + +```js { block : 'button', - text : 'Small', - mods : { theme : 'islands', size : 's' } + mods : { theme : 'islands', size : 'm', disabled : true }, + text : 'Disabled' } ``` -```bemjson + + +#### `focused` modifier + +Available value: `true`. + +Use case: `BEMJSON`, `JS`. + +The modifier provides a focus to the block. + +```javascript { block : 'button', - text : 'Medium', - mods : { theme : 'islands', size : 'm' } + mods : { theme : 'islands', size : 'm', focused : true }, + text : 'In focus' } ``` -```bemjson + + +#### `pressed` modifier + +Available value: `true`. + +Use case: – . + +The modifier is added to a button automatically at the moment when the button is pressed. + +This modifier is used for buttons with togglable modifier. + + + +#### `hovered` modifier + +Available value: `true`. + +Use case: – . + +The modifier is added to a block automatically at the moment when you mouse over it. + + + +#### `theme` modifier + +Available value: `'islands'`. + +Use case: `BEMJSON`. + +If `theme` modifier is not specified, native representation of a control is applied. + +**NB** `islands` theme requires size modifier usage. + +```js { block : 'button', - text : 'Large', - mods : { theme : 'islands', size : 'l' } + mods : { theme : 'islands', size : 'm' }, + text : 'Islands theme' } ``` -```bemjson + + +#### `size` modifier + +Available values for `islands` theme: `'s'`, `'m'`, `'l'`, `'xl'`. + +Use case: `BEMJSON`. + +Use `size` modifier only for blocks with `islands` theme. + +Provides all types of buttons with `size` value. + +**s** + +```js { block : 'button', - text : 'X-large', - mods : { theme : 'islands', size : 'xl' } + mods : { theme : 'islands', size : 's' }, + text : 'Size s' } ``` -### _type +**m** -If `type` modifier is not specified for the block, islands button will be represented by default. +```js +{ + block : 'button', + mods : { theme : 'islands', size : 'm' }, + text : 'Size m' +} +``` - -#### Button with link behavior +**l** -Use `type` modifier with `link` value to create a button that behaves like a link. +```js +{ + block : 'button', + mods : { theme : 'islands', size : 'l' }, + text : 'Size l' +} +``` -Specify additional `url` attribute in BEMJSON input data for this button type. +**xl** -```bemjson +```js { block : 'button', - url : '#', - text : 'Link behavior', - mods : { theme : 'islands', size : 'm', type : 'link' } + mods : { theme : 'islands', size : 'xl' }, + text : 'Size xl' } ``` -#### Form submit button + + +#### `view` modifier -Use `type` modifier with `submit` value to create a button for data sending to a server (submit). This button type implemented for buttons located inside a form. +Available values: `'action'`, `'pseudo'`. -```bemjson +Use case: `BEMJSON`. + +##### An action button (`view` modifier with `action` value) + +The modifier visually highlights a button on a page. For example, use it to create a promo button: + +```js { block : 'button', - text : 'Submit', - mods : { theme : 'islands', size : 'm', type : 'submit' } + mods : { theme : 'islands', size : 'm', view : 'action' }, + text : 'Buy now!' } ``` -### States of a block +##### A pseudobutton (`view` modifier with `pseudo` value) -#### _disabled +The modifier changes visual representation of a button. For example, use it if you do not need to focus attention on the button: -`disabled` modifier is used to make block visible but not available for user action. It cannot be focused, pressed or hovered. In most cases to mark out the disabled block on a page, additional styles are applied. +```js +{ + block : 'button', + mods : { theme : 'islands', size : 'm', view : 'pseudo' }, + text : 'With transparent background' +} +``` -```bemjsom +```js { block : 'button', - text : 'Disabled', - mods : { theme : 'islands', size : 'm', disabled : true } + mods : { theme : 'islands', size : 'm', view : 'pseudo', disabled : true }, + text : 'Without boarders' } ``` -#### _focused +### Custom fields of the block -When a block is focused, a modifier `focused` with `true` value is set automatically, e.g. by pressing `Tab` or clicking a mouse. + -#### _togglable +#### `name` field -Defines a behavior of the pressed button. +Type: `String`. -The following values of `togglable` modifier are available: +Specifies a unique name of the block. -* `check` – the first click presses the button, and the second releases it. +Do not use `name` field for type modifier with link value. -```bemjson +```js { block : 'button', - text : 'Check', - mods : { theme : 'islands', size : 'm', togglable : 'check' }, + mods : { theme : 'islands', size : 'm', type : 'submit' }, + name : 'Test_1', + val : 'passed', + text : 'Check results' } ``` -* `radio` – the first click presses the button and it cannot be released by the next click. + + +#### `val` field + +Type: `String`, `Number`. + +Specifies a value that is sent to a server. -```bemjson +Do not use `val` field for type modifier with link value. + +```js { block : 'button', - text : 'Radio', - mods : { theme : 'islands', size : 'm', togglable : 'radio' } + mods : { theme : 'islands', size : 'm', type : 'submit' }, + name : 'Test_1', + val : 'passed', + text : 'Check results' } ``` -#### _hovered -Defines “hovered” state of a button. +#### `text` field -#### _pressed +Type: `String`. -Defines “pressed” state of a button. +Specifies a text on a button. -### _view +```js +{ + block : 'button', + mods : { theme : 'islands', size : 'm', type : 'submit' }, + name : 'Test_1', + val : 'passed', + text : 'Check results' +} +``` + + -#### _action +#### `url` field -Implemented only for theme `islands`. +Type: `String`. -Visually highlights a button with yellow colour on a page. Could be used as a promo button. +Specifies a link address that will be opened by clicking a link-button. -```bemjson +Use `url` field for a link-buttons only. + +```js { block : 'button', - type : 'submit', - text : 'Action', - mods : { theme : 'islands', size : 'm', view : 'action' } + mods : { theme : 'islands', size : 'm', type : 'link' }, + url : 'https://bem.info/', + text : 'Try BEM!' } ``` -#### _pseudo +#### `icon` field -Implemented only for theme `islands`. +Type: `BEMJSON`. -This modifier changes visual representation of a button. With `view` modifier set to `pseudo`, the background of a button becomes transparent. +Specifies an icon on a button. Declare the icon in BEMJSON using [icon](../icon/icon.en.md) block. -```bemjson +```js { block : 'button', - text : 'Pseudo', - mods : { theme : 'islands', size : 'm', view : 'pseudo' } + mods : { theme : 'islands', size : 'm' }, + text : 'Twitter', + icon : { + block : 'icon', + mods : { social : 'twitter' } + } } ``` -If pseudo button is disabled, its borders disappear. + + +#### `title` title -```bemjson +Type: `String`. + +Specifies a tooltip content. The tooltip appearance depends on a browser and your operating system settings. You cannot change it applying HTML or different styles. + +```js { block : 'button', - text : 'Disabled', - mods : { theme : 'islands', size : 'm', view : 'pseudo', disabled : true } + mods : { theme : 'islands', size : 'm', type : 'submit' }, + name : 'Test #1', + val : 'Passed', + text : 'Check the result', + title : 'This button shows the test results' } ``` -## Elements of a block + + +#### `id` field -### __text +Type: `String`. -An auxiliary element that is added to the block on template engine level. +Specifies a unique identifier of a button. + +```js +{ + block : 'button', + mods : { theme : 'islands', size : 'm', type : 'submit' }, + name : 'Test #1', + val : 'Passed', + text : 'Check the result', + id : 'Unique_1' +} +``` + + + +#### `tabIndex` field + +Type: `Number`. + +Specifies a tab order between controls on a page by pressing `Tab`. + +```js +{ + block : 'button', + mods : { theme : 'islands', size : 'm', type : 'submit' }, + name : 'Test #1', + val : 'Passed', + text : 'Check the result', + tabIndex : 3 +} +```