Skip to content

Commit

Permalink
Merge pull request #32 from pebble/#31/generic-btn-component
Browse files Browse the repository at this point in the history
Add generic button component
  • Loading branch information
keegan-lillo committed Mar 7, 2016
2 parents 20e7460 + c4f6b17 commit 49f92de
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 45 deletions.
60 changes: 48 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Sections help divide up the page into logical groups of items. It is recommended

### Heading

**Manipulator:** `html`
**Manipulator:** [`html`](#html)

Headings can be used in anywhere and can have their size adjusted to suit the context. If you place a heading item at the first position of a section's `items` array then it will automatically be styled as the header for that section.

Expand Down Expand Up @@ -138,7 +138,7 @@ Headings can be used in anywhere and can have their size adjusted to suit the co

### Text

**Manipulator:** `html`
**Manipulator:** [`html`](#html)

Text is used to provide descriptions of sections or to explain complex parts of your page. Feel free to add any extra HTML you require to the `defaultValue`

Expand All @@ -165,7 +165,7 @@ Text is used to provide descriptions of sections or to explain complex parts of

### Input

**Manipulator:** `val`
**Manipulator:** [`val`](#val)

Standard text input field.

Expand Down Expand Up @@ -203,7 +203,7 @@ Standard text input field.

#### Toggle

**Manipulator:** `checked`
**Manipulator:** [`checked`](#checked)

Switch for a single item.

Expand Down Expand Up @@ -238,7 +238,7 @@ Switch for a single item.

#### Select

**Manipulator:** `val`
**Manipulator:** [`val`](#val)

A dropdown menu containing multiple options.

Expand Down Expand Up @@ -291,7 +291,7 @@ A dropdown menu containing multiple options.

#### Color

**Manipulator:** `color`
**Manipulator:** [`color`](#color)

A color picker containing the 64 supported colors on Basalt and Chalk.

Expand Down Expand Up @@ -321,9 +321,9 @@ A color picker containing the 64 supported colors on Basalt and Chalk.

---

#### RadioGroup
#### Radio Group

**Manipulator:** `radiogroup`
**Manipulator:** [`radiogroup`](#radiogroup)

A list of options allowing the user can only choose one option to submit.

Expand Down Expand Up @@ -366,9 +366,9 @@ A list of options allowing the user can only choose one option to submit.

---

#### CheckboxGroup
#### Checkbox Group

**Manipulator:** `checkboxgroup`
**Manipulator:** [`checkboxgroup`](#checkboxgroup)

A list of options where a user may choose more than one option to submit.

Expand Down Expand Up @@ -412,9 +412,35 @@ A list of options where a user may choose more than one option to submit.

---

### Generic Button

**Manipulator:** [`button`](#button)

##### Properties

| Property | Type | Description |
|----------|------|-------------|
| type | string | Set to `button`. |
| defaultValue | string | The text displayed on the button. |
| primary | boolean | If `true` the button will be orange, if `false`, the button will be gray (defaults to `false`)|
| attributes | object | An object containing HTML attributes to set on the input field. |
| description | string | Optional sub-text to include below the component |

##### Example

```javascript
{
"type": "button",
"primary": true,
"defaultValue": "Send"
}
```

---

### Submit

**Manipulator:** `html`
**Manipulator:** [`button`](#button)

The submit button for the page. You **MUST** include this component somewhere in the config page (traditionally at the bottom) or users will not be able to save the form.

Expand All @@ -440,7 +466,6 @@ The submit button for the page. You **MUST** include this component somewhere in
### Coming Soon

- Range Slider
- Generic Button
- Tabs
- Footer
- Dynamic + draggable list
Expand Down Expand Up @@ -468,6 +493,17 @@ Eg: If you run the `.show()` manipulator on an item that is already visible, the
| `.hide()` | `ClayItem` | `hide` | Hides the item |
| `.show()` | `ClayItem` | `show` | Shows the item |

#### button

| Method | Returns | Event Fired | Description |
|--------|---------|-------------| ------------|
| `.set( [string\|HTML] value)` | `ClayItem` | `change` | Sets the content of this item. |
| `.get()` | `string` | | Gets the content of this item. |
| `.disable()` | `ClayItem` | `disabled` | Prevents this item from being clicked by the user. |
| `.enable()` | `ClayItem` | `enabled` | Allows this item to be clicked by the user. |
| `.hide()` | `ClayItem` | `hide` | Hides the item |
| `.show()` | `ClayItem` | `show` | Shows the item |

#### val

| Method | Returns | Event Fired | Description |
Expand Down
8 changes: 8 additions & 0 deletions dev/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ module.exports = [
"defaultValue": "00FF00",
"label": "Sunny Color Picker",
"sunlight": true
},
{
type: 'button',
id: 'testButton',
primary: false,
defaultValue: 'Generic Button',
description: 'This is a generic button. ' +
'You can listen for standard events like "click"'
}
]
},
Expand Down
Binary file modified src/images/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/scripts/components/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = {
name: 'button',
template: require('../../templates/components/button.tpl'),
style: require('../../styles/clay/components/button.scss'),
manipulator: 'button',
defaults: {
primary: false,
attributes: {},
description: ''
}
};
3 changes: 2 additions & 1 deletion src/scripts/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = {
text: require('./text'),
toggle: require('./toggle'),
radiogroup: require('./radiogroup'),
checkboxgroup: require('./checkboxgroup')
checkboxgroup: require('./checkboxgroup'),
button: require('./button')
};
2 changes: 1 addition & 1 deletion src/scripts/components/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
name: 'submit',
template: require('../../templates/components/submit.tpl'),
style: require('../../styles/clay/components/submit.scss'),
manipulator: 'html',
manipulator: 'button',
defaults: {
attributes: {}
}
Expand Down
14 changes: 14 additions & 0 deletions src/scripts/lib/manipulators.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ module.exports = {
hide: hide,
show: show
},
button: {
get: function() {
return this.$manipulatorTarget.get('innerHTML');
},
set: function(value) {
if (this.get() === value.toString(10)) { return this; }
this.$manipulatorTarget.set('innerHTML', value);
return this.trigger('change');
},
disable: disable,
enable: enable,
hide: hide,
show: show
},
val: {
get: function() {
return this.$manipulatorTarget.get('value');
Expand Down
1 change: 1 addition & 0 deletions src/styles/clay/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ label {
padding: 0 $item-spacing-h $item-spacing-v ;
@include font-size(0.9);
color: $color-gray-9;
text-align: left;
}

.inputs {
Expand Down
4 changes: 2 additions & 2 deletions src/styles/clay/_vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $color-gray-9: #a4a4a4 ;
$color-gray-10: #ececec;
$color-gray-11: #f2f2f2;

$button-padding: 0.7rem;
$button-padding-ios: 0.6rem;
$button-padding: 0.6rem;
$button-padding-ios: 0.5rem;

$box-shadow-small-components: $color-gray-1 0 0.1rem 0.1rem;
12 changes: 12 additions & 0 deletions src/styles/clay/components/button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.component-button {
text-align: center;

.section & {
padding-bottom: 0;
}

.description {
padding-left: 0;
padding-right: 0;
}
}
36 changes: 7 additions & 29 deletions src/styles/clay/elements/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,30 @@
button,
.button {
@include font-pfdin(medium);
@include font-size(1);
text-transform: uppercase;
background-color: $color-gray-4;
background-color: $color-gray-7;
border-radius: $border-radius;
font-size: 1rem;
line-height: 1;
border: none;
display: inline-block;

color: $color-white;
min-width: 12rem;
text-align: center;
margin: 0 auto;
-webkit-tap-highlight-color: rgba(0,0,0,0);

margin: 0 auto $item-spacing-v;
padding: $button-padding;

@include tap-highlight($color-gray-8);

.platform-ios & {
padding: $button-padding-ios;
}

&:disabled {
background-color: $color-gray-3;
color: $color-gray-8;
}

&:not(:disabled):active {
background-color: $color-gray-8;
}

&.orange, &[type="submit"] {
&.primary, &[type="submit"] {
background-color: $color-orange;

&:disabled {
background-color: $color-orange-dark;
color: $color-gray-3;
}

&:not(:disabled):active {
background-color: $color-red;
}
@include tap-highlight($color-red);
}

&.light-grey {
background-color: $color-gray-5;
}

}

a.button {
Expand Down
11 changes: 11 additions & 0 deletions src/templates/components/button.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="component component-button">
<button
type="button"
data-manipulator-target
class="{{primary ? 'primary' : ''}}"
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
></button>
{{if description}}
<div class="description">{{{description}}}</div>
{{/if}}
</div>
10 changes: 10 additions & 0 deletions test/spec/lib/manipulators.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,20 @@ describe('manipulators', function() {

describe('html', function() {
testSetGet('text', 'test123');
testSetGet('button', '<span>some HTML</span>');
testShow('text');
testHide('text');
});

describe('button', function() {
testSetGet('button', 'test123');
testSetGet('button', '<span>some HTML</span>');
testDisable('button');
testEnable('button');
testShow('button');
testHide('button');
});

describe('val', function() {
testSetGet('input', 'test321');
testSetGet('input', 1234, '1234');
Expand Down

0 comments on commit 49f92de

Please sign in to comment.