Skip to content

Commit

Permalink
refactor: add new bolt-li shared component; update package.json and .…
Browse files Browse the repository at this point in the history
…boltrc accordingly
  • Loading branch information
sghoweri committed Dec 17, 2018
1 parent 65c6cf0 commit c9a4ed6
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 14 deletions.
4 changes: 2 additions & 2 deletions apps/pattern-lab/.boltrc.js
Expand Up @@ -103,7 +103,6 @@ const config = {
'@bolt/components-navbar',
'@bolt/components-navlink',
'@bolt/components-logo',
'@bolt/components-ordered-list',
'@bolt/components-page-footer',
'@bolt/components-page-header',
'@bolt/components-pagination',
Expand All @@ -116,7 +115,8 @@ const config = {
'@bolt/components-teaser',
'@bolt/components-text',
'@bolt/components-tooltip',
'@bolt/components-unordered-list',
'@bolt/components-ul',
'@bolt/components-ol',
'@bolt/components-video',
'@bolt/components-grid',
/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -80,6 +80,7 @@
"packages/build-tools",
"packages/build-tools/plugins/*",
"packages/components/*",
"packages/components/lists/*",
"packages/config-presets/*",
"packages/core",
"packages/twig-renderer",
Expand Down
7 changes: 7 additions & 0 deletions packages/components/lists/bolt-li/README.md
@@ -0,0 +1,7 @@
List item helper element used by other list-like components (like `<bolt-ul>` and `<bolt-ol>`).

###### Install via NPM

```
npm install @bolt/components-li
```
5 changes: 5 additions & 0 deletions packages/components/lists/bolt-li/index.js
@@ -0,0 +1,5 @@
import { polyfillLoader } from '@bolt/core/polyfills';

polyfillLoader.then(res => {
import(/* webpackMode: 'eager', webpackChunkName: 'bolt-li' */ './src/li');
});
1 change: 1 addition & 0 deletions packages/components/lists/bolt-li/index.scss
@@ -0,0 +1 @@
@import 'src/li';
11 changes: 11 additions & 0 deletions packages/components/lists/bolt-li/li.schema.yml
@@ -0,0 +1,11 @@
title: List Item
type: object
require:
- items
properties:
attributes:
type: object
description: A Drupal-style attributes object with extra attributes to append to this component.
item:
type: [string, object, array]
description: Renderable content (i.e. a string, render array, or included pattern) for a single list item.
38 changes: 38 additions & 0 deletions packages/components/lists/bolt-li/package.json
@@ -0,0 +1,38 @@
{
"name": "@bolt/components-li",
"description": "Bolt List Item Component",
"keywords": [
"bolt design system",
"bolt",
"css framework",
"design system",
"components"
],
"version": "2.2.0",
"maintainers": [
{
"name": "Salem Ghoweri",
"email": "me@salemghoweri.com",
"web": "https://github.com/sghoweri"
},
{
"name": "Mike Mai",
"email": "boss@mikemai.net",
"web": "http://mikemai.net/"
}
],
"homepage": "https://boltdesignsystem.com",
"license": "MIT",
"repository": "https://github.com/bolt-design-system/bolt/tree/master/packages/components/lists/bolt-li",
"bugs": "https://github.com/bolt-design-system/bolt/issues",
"style": "index.scss",
"main": "index.js",
"twig": "src/li.twig",
"schema": "li.schema.yml",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@bolt/core": "^2.2.0"
}
}
54 changes: 54 additions & 0 deletions packages/components/lists/bolt-li/src/li.js
@@ -0,0 +1,54 @@
import { define, props, mapWithDepth } from '@bolt/core/utils';
import classNames from 'classnames/bind';
import { withLitHtml, html } from '@bolt/core/renderers/renderer-lit-html';

import styles from './li.scss';

let cx = classNames.bind(styles);

@define
class BoltListItem extends withLitHtml() {
static is = 'bolt-li';

static props = {
level: {
...props.number,
...{ default: 1 },
},
type: {
...props.string,
...{ default: 'ul' },
},
};

connected() {
this.level = this.parentNode.level ? this.parentNode.level : this.props.level;
this.type = this.parentNode.tagName === 'BOLT-OL' ? 'ol' : 'ul';
}

render() {
// this.level = this.parentNode.level ? this.parentNode.level : this.level;

const classes = cx('c-bolt-li', {
[`c-bolt-li--l${this.level}`]: this.level,
[`c-bolt-li--${this.type}-item`]: this.type,
[`c-bolt-li--level-${this.level % 3 !== 0 ? this.level % 3 : 3}`]: this.level, // allow up to 3 levels of nested styles before repeating
});

// helper function called by the mapWithDepth util to increment the depth of nested children
function addNestedLevelProps(childNode, depth) {
childNode.level = depth + 1;
}

this.slots.default = this.slots.default.map(
mapWithDepth(this.level, addNestedLevelProps),
);

return html`
${this.addStyles([styles])}
<li class="${classes}">${this.slot('default')}</li>
`;
}
}

export { BoltListItem };
131 changes: 131 additions & 0 deletions packages/components/lists/bolt-li/src/li.scss
@@ -0,0 +1,131 @@
@import '@bolt/core';

// Local Variables
$bolt-li-bullet-size: 6px; // Using px here because I need to make a perfect circle without subpixel issues.

// Local Variables
$bolt-ol-bullet-size: $bolt-line-height--xsmall + rem;
$bolt-ol-bullet-bg-color: rgba(bolt-color(gray), 0.2);

bolt-li {
display: list-item;
}

.c-bolt-li {
box-sizing: border-box;
position: relative;
margin-bottom: bolt-spacing(xxsmall);
// margin-left: bolt-spacing(small) + bolt-spacing(xsmall);
margin-left: bolt-spacing(medium);
@include bolt-padding(0);

.c-bolt-li:before {
background-color: transparent;
}
}




.c-bolt-li--ul-item {
&:before {
content: '';
display: block;
box-sizing: border-box;
position: absolute;
top: calc(0.55rem + 1px);
left: bolt-spacing(small) * -2;
width: $bolt-li-bullet-size;
height: $bolt-li-bullet-size;
line-height: $bolt-li-bullet-size;
border: 1px solid bolt-theme(headline);
border-radius: $bolt-li-bullet-size;
background-color: bolt-theme(headline);
}

// &.c-bolt-li--level-2:before {
// background-color: transparent;
// }

// &.c-bolt-li--level-3:before {
// border-radius: 0;
// background-color: bolt-theme(headline);
// }
}





// &.c-bolt-li--level-3:before {
// border-radius: 0;
// background-color: bolt-theme(headline);
// }


// bolt-ol-item {
// position: relative;

// &:before {
// @include bolt-font-size(xsmall);
// @include bolt-font-weight(bold);

// // content: counter(li);
// // display: block;
// // position: absolute;
// // top: 0.125em;
// // left: 0;
// // width: $bolt-ol-bullet-size;
// // height: $bolt-ol-bullet-size;
// // counter-increment: li;
// // color: bolt-theme(headline);
// // line-height: $bolt-ol-bullet-size;
// // text-align: center;
// // border-radius: $bolt-ol-bullet-size;
// // background-color: $bolt-ol-bullet-bg-color;
// }
// }

// .c-bolt-ol-item {
// @include bolt-margin(0 0 0 medium);
// @include bolt-padding(0);

// position: relative;

// &__content {
// @include bolt-margin-bottom(small);
// }

// &--last-item {
// @include bolt-margin-bottom(0);
// }
// }
.c-bolt-li--ol-item {
// @include bolt-margin(0 0 0 medium);
}

.c-bolt-li--ol-item:before {
@include bolt-font-size(xsmall);
@include bolt-font-weight(bold);
content: counter(li);
display: block;
position: absolute;
top: 0.125em;
// left: 0;
left: bolt-spacing(small) * -2;
width: $bolt-ol-bullet-size;
height: $bolt-ol-bullet-size;
counter-increment: li;
color: bolt-theme(headline);
line-height: $bolt-ol-bullet-size;
text-align: center;
border-radius: $bolt-ol-bullet-size;
background-color: $bolt-ol-bullet-bg-color;
}

// [Mai] This is an IE specific fix to center the number inside the circle. IE calculates line-height differently.
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
.c-bolt-li--ol-item:before {
line-height: $bolt-line-height--medium;
}
}
38 changes: 38 additions & 0 deletions packages/components/lists/bolt-li/src/li.twig
@@ -0,0 +1,38 @@
{% set attributes = create_attribute(attributes|default({})) %}
{% set base_class = "c-bolt-li" %}

{% set last = loop.last %}
{% set classes = [
"#{base_class}",
type ? "#{base_class}--#{type}-item",
] %}

{% if item.text %}
{% set children = item.text %}
{% elseif item.children %}
{% set children = item.children %}
{% elseif item %}
{% set children = item %}
{% endif %}

<bolt-li {{ attributes }}>
<replace-with-grandchildren>
<li class="{{ classes|join(" ") }}">
{{ children }}

{# {% if item is iterable %}
{% for i in item %}
{% set inner_item_attributes = create_attribute({}) %}
{% set last_i = loop.last %}
{% set inner_classes = [
"#{base_class}bolt-ordered-list",
last and last_i ? "#{base_class}--last-item",
] %}
{{ i }}
{% endfor %}
{% else %}
{{ item }}
{% endif %} #}
</li>
</replace-with-grandchildren>
</bolt-li>
32 changes: 20 additions & 12 deletions yarn.lock
Expand Up @@ -704,11 +704,25 @@
node-fetch "^2.1.2"
sleep-promise "^8.0.1"

"@bolt/components-ordered-list@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@bolt/components-ordered-list/-/components-ordered-list-2.2.0.tgz#c0a2cbd01f4b50cf62747d5f771605b608527440"
integrity sha512-GiuwXH7m1H6M3gqFYhuFuNPRIO0hMC+aTuvplnSd+C2d8PKjH6qos9Nc6329RBOg+Imc3yCkL/4CL+JnW7fm2Q==
dependencies:
"@bolt/core" "^2.2.0"

"@bolt/components-page-footer@file:packages/components/bolt-page-footer":
version "2.2.0"
dependencies:
"@bolt/core" "^2.2.0"

"@bolt/components-unordered-list@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@bolt/components-unordered-list/-/components-unordered-list-2.2.0.tgz#a2135aa6677fdec5b68664ee7e58d3a794ec0239"
integrity sha512-TELdbQSdphJGTLAj1khrXMGp5P3Q+KF+i9BhINEc9vTQMEaYQeETLn5ix+tqPPO7O4GGPx1GcNzVG8UwQkc3zA==
dependencies:
"@bolt/core" "^2.2.0"

"@bolt/fast-sass-loader@github:bolt-design-system/fast-sass-loader#master":
version "1.4.5"
resolved "https://codeload.github.com/bolt-design-system/fast-sass-loader/tar.gz/14eb5a6c1f13b89f13a71b348a58aa61f59b434f"
Expand Down Expand Up @@ -1360,11 +1374,6 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.10.tgz#4fa76e6598b7de3f0cb6ec3abacc4f59e5b3a2ce"
integrity sha512-8xZEYckCbUVgK8Eg7lf5Iy4COKJ5uXlnIOnePN0WUwSQggy9tolM+tDJf7wMOnT/JT/W9xDYIaYggt3mRV2O5w==

"@types/tapable@1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd"
integrity sha512-42zEJkBpNfMEAvWR5WlwtTH22oDzcMjFsL9gDGExwF8X8WvAiw7Vwop7hPw03QT8TKfec83LwbHj6SvpqM4ELQ==

"@vue/babel-preset-app@^3.1.0":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@vue/babel-preset-app/-/babel-preset-app-3.1.1.tgz#1bb6395c5ddc84bc8e993ace47151b0d95d382a7"
Expand Down Expand Up @@ -7766,7 +7775,7 @@ html-loader@^0.5.5:
loader-utils "^1.1.0"
object-assign "^4.1.1"

html-minifier@^3.2.3, html-minifier@^3.3.1, html-minifier@^3.5.8:
html-minifier@^3.2.3, html-minifier@^3.3.1, html-minifier@^3.5.20, html-minifier@^3.5.8:
version "3.5.21"
resolved "https://registry.yarnpkg.com/html-minifier/-/html-minifier-3.5.21.tgz#d0040e054730e354db008463593194015212d20c"
integrity sha512-LKUKwuJDhxNa3uf/LPR/KVjm/l3rBqtYeCOAekvG8F1vItxMUpueGd94i/asDDr8/1u7InxzFA5EeGjhhG5mMA==
Expand Down Expand Up @@ -7810,12 +7819,11 @@ html-webpack-plugin@^3.2.0:
version "4.0.0-beta"
resolved "https://codeload.github.com/jantimon/html-webpack-plugin/tar.gz/7fb656a2dfdf129162f993a260f3291336b17ff1"
dependencies:
"@types/tapable" "1.0.2"
html-minifier "^3.2.3"
html-minifier "^3.5.20"
loader-utils "^1.1.0"
lodash "^4.17.10"
pretty-error "^2.0.2"
tapable "^1.0.0"
lodash "^4.17.11"
pretty-error "^2.1.1"
tapable "^1.1.0"
util.promisify "1.0.0"

htmlparser2@3.8.x, htmlparser2@~3.8.1:
Expand Down Expand Up @@ -13154,7 +13162,7 @@ pretty-bytes@^4.0.2:
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-4.0.2.tgz#b2bf82e7350d65c6c33aa95aaa5a4f6327f61cd9"
integrity sha1-sr+C5zUNZcbDOqlaqlpPYyf2HNk=

pretty-error@^2.0.2:
pretty-error@^2.0.2, pretty-error@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/pretty-error/-/pretty-error-2.1.1.tgz#5f4f87c8f91e5ae3f3ba87ab4cf5e03b1a17f1a3"
integrity sha1-X0+HyPkeWuPzuoerTPXgOxoX8aM=
Expand Down

0 comments on commit c9a4ed6

Please sign in to comment.