Skip to content

Commit 9eb15aa

Browse files
authored
Merge pull request #14 from adidas/feature/add-yarn-design-system
Improve example and documentationmn
2 parents 580a869 + 9c605a4 commit 9eb15aa

File tree

7 files changed

+136
-44
lines changed

7 files changed

+136
-44
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ script:
1414
- if [[ $TRAVIS_TAG =~ $TAG_REGEX ]];
1515
then
1616
npm run doc;
17-
npm run copy:example;
17+
npm run example;
1818
fi
1919

2020
deploy:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.5.1
2+
3+
- Added ReactJS documentation.
4+
- Updated project description and documentation.
5+
- Updated demo adding repository link.
6+
- Fixed external links with `rel="noopener"`.
7+
18
# 1.5.0
29

310
- Updated `choices.js` to version `9.0.1`.

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
# ChoicesJS Web Component
88

9-
Select component which just wraps [ChoicesJS][choicesjs] in a real [Web Component][web-component]. It has been created using [StencilJS][stenciljs], and written with [_Typescript_][typescript] and [_JSX_][jsx].
9+
Select and multi-select Web Component which transforms [ChoicesJS][choicesjs] library into a real [Web Component][web-component].
1010

1111
This component allows the user to select from dropdowns, to browser between multiple options, to add tags to an input, etc.
1212

1313
Play with it on the [**demo**][demo] page.
1414

15+
It is built with [StencilJS][stenciljs], and written in [_Typescript_][typescript] and [_JSX_][jsx].
16+
1517
## Use cases
1618

1719
The purpose of this project is to create a simple Web Component wrapper from the [ChoicesJS][choicesjs] library.
@@ -155,6 +157,56 @@ export default {
155157
</script>
156158
```
157159

160+
#### Example for ReactJS framework
161+
162+
```javascript
163+
// Loading ChoicesJS library and ChoicesJS Stencil Web Component
164+
import 'expose-loader?Choices!choices.js';
165+
import { defineCustomElements } from 'choicesjs-stencil/dist/loader';
166+
167+
defineCustomElements(window);
168+
169+
// ReactJS component
170+
import React, { useEffect, useRef } from 'react';
171+
172+
export default function ChoicesJSStencil({
173+
type = 'text',
174+
name,
175+
choices = [],
176+
onChange
177+
}) {
178+
const choicesElement = useRef(null);
179+
180+
useEffect(() => {
181+
const { current } = choicesElement;
182+
const _handleChange = handleChange.bind(null, onChange);
183+
184+
current.choices = choices;
185+
current.addEventListener('change', _handleChange);
186+
187+
return () => {
188+
current.removeEventListener('change', _handleChange);
189+
};
190+
}, [ choices ]);
191+
192+
async function handleChange(callback) {
193+
const { current } = choicesElement;
194+
195+
callback({
196+
options: await current.getValue(true),
197+
target: current
198+
});
199+
}
200+
201+
return (
202+
<choicesjs-stencil class="choicesjs-stencil"
203+
ref={ choicesElement }
204+
type={ type }
205+
name={ name } />
206+
);
207+
}
208+
```
209+
158210
### Configuration
159211

160212
- `type`: the type of selector to render, defaults to `text`. Options: `text`, `single`, `multiple`.

assets/github-logo-64x64.png

2.28 KB
Loading

index.html

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,33 @@
1010
<script src="dist/choicesjsstencil.js"></script>
1111
<style>
1212
html {
13-
font-size: 14px;
14-
margin-top: .5rem;
13+
font-size: 16px;
1514
}
1615
body {
17-
padding-bottom: 4rem;
16+
padding-bottom: 3rem;
17+
}
18+
.header {
19+
background-color: #000;
20+
margin-bottom: 2rem;
21+
height: 3.5rem;
22+
display: flex;
23+
align-items: center;
24+
}
25+
.header__left {
26+
color: #fff;
27+
font-weight: 700;
28+
flex: 1 0 auto;
29+
}
30+
.header__left h2,
31+
.header__left h3 {
32+
margin: 0 .5rem;
33+
}
34+
.header__right .header__icon {
35+
padding: .25rem;
36+
display: block;
37+
}
38+
.header__right .header__icon img {
39+
width: 3rem;
1840
}
1941
.select-container {
2042
display: inline-flex;
@@ -67,10 +89,18 @@
6789
<style id="customStyles"></style>
6890
</head>
6991
<body>
70-
<div class="container-fluid">
71-
<div class="row">
72-
<h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
92+
<header class="header">
93+
<div class="header__left">
94+
<h2 class="hidden-xs">ChoicesJS Web Component: test page</h2>
95+
<h3 class="visible-xs">ChoicesJS Web Component</h3>
96+
</div>
97+
<div class="header__right">
98+
<a class="header__icon" href="https://github.com/adidas/choicesjs-stencil" target="blank" rel="noopener">
99+
<img src="assets/github-logo-64x64.png">
100+
</a>
73101
</div>
102+
</header>
103+
<div class="container-fluid">
74104
<div class="row">
75105
<form class="col-sm-12 select-container" name="choicesjs-stencil-form">
76106
<choicesjs-stencil name="select" class="select"></choicesjs-stencil>
@@ -497,7 +527,9 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
497527
</textarea>
498528
<label for="callbackOnCreateTemplates">}</label>
499529
<br/>
500-
<a href="https://github.com/jshjohnson/Choices/blob/v9.0.1/public/assets/scripts/choices.js#L2777-L2926" target="_blank">
530+
<a href="https://github.com/jshjohnson/Choices/blob/v9.0.1/public/assets/scripts/choices.js#L2777-L2926"
531+
target="_blank"
532+
rel="noopener">
501533
Templates reference
502534
</a>
503535
</div>
@@ -523,7 +555,7 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
523555
<div class="col-md-12">
524556
<p class="text-center pad-top">
525557
See full documentation in
526-
<a href="https://www.npmjs.com/package/choices.js/v/9.0.1" target="_blank">choices.js</a>
558+
<a href="https://www.npmjs.com/package/choices.js/v/9.0.1" target="_blank" rel="noopener">choices.js</a>
527559
npm package.
528560
</p>
529561
</div>
@@ -555,39 +587,40 @@ <h4 class="modal-title">Custom Styles</h4>
555587
<div class="row">
556588
<div class="col-md-6">
557589
<textarea class="form-control textarea--fixed" name="classNames" rows="26">
558-
{
559-
"containerOuter": "choices",
560-
"containerInner": "choices__inner",
561-
"input": "choices__input",
562-
"inputCloned": "choices__input--cloned",
563-
"list": "choices__list",
564-
"listItems": "choices__list--multiple",
565-
"listSingle": "choices__list--single",
566-
"listDropdown": "choices__list--dropdown",
567-
"item": "choices__item",
568-
"itemSelectable": "choices__item--selectable",
569-
"itemDisabled": "choices__item--disabled",
570-
"itemChoice": "choices__item--choice",
571-
"placeholder": "choices__placeholder",
572-
"group": "choices__group",
573-
"groupHeading": "choices__heading",
574-
"button": "choices__button",
575-
"activeState": "is-active",
576-
"focusState": "is-focused",
577-
"openState": "is-open",
578-
"disabledState": "is-disabled",
579-
"highlightedState": "is-highlighted",
580-
"selectedState": "is-selected",
581-
"flippedState": "is-flipped",
582-
"loadingState": "is-loading",
583-
"noResults": "has-no-results",
584-
"noChoices": "has-no-choices"
585-
}
590+
{
591+
"containerOuter": "choices",
592+
"containerInner": "choices__inner",
593+
"input": "choices__input",
594+
"inputCloned": "choices__input--cloned",
595+
"list": "choices__list",
596+
"listItems": "choices__list--multiple",
597+
"listSingle": "choices__list--single",
598+
"listDropdown": "choices__list--dropdown",
599+
"item": "choices__item",
600+
"itemSelectable": "choices__item--selectable",
601+
"itemDisabled": "choices__item--disabled",
602+
"itemChoice": "choices__item--choice",
603+
"placeholder": "choices__placeholder",
604+
"group": "choices__group",
605+
"groupHeading": "choices__heading",
606+
"button": "choices__button",
607+
"activeState": "is-active",
608+
"focusState": "is-focused",
609+
"openState": "is-open",
610+
"disabledState": "is-disabled",
611+
"highlightedState": "is-highlighted",
612+
"selectedState": "is-selected",
613+
"flippedState": "is-flipped",
614+
"loadingState": "is-loading",
615+
"noResults": "has-no-results",
616+
"noChoices": "has-no-choices"
617+
}
586618
</textarea>
587619
</div>
588620
<div class="col-md-6">
589621
<textarea class="form-control textarea--fixed" name="styles" rows="26">
590-
/* Add any custom classes for the component */
622+
/* Add any custom classes for the component */
623+
/* .choices__input { font-style: italic; } */
591624
</textarea>
592625
</div>
593626
</div>
@@ -609,7 +642,7 @@ <h4 class="modal-title">Search options</h4>
609642
</div>
610643
<div class="modal-body">
611644
<h5 class="text-center pad-bottom">
612-
See full Fuse documentation in <a href="https://fusejs.io/" target="_blank">GitHub</a>.
645+
See full Fuse documentation in <a href="https://fusejs.io/" target="_blank" rel="noopener">GitHub</a>.
613646
</h5>
614647
<form name="custom-search-form">
615648
<div class="form-group">

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "choicesjs-stencil",
3-
"version": "1.5.0",
4-
"description": "Select Web Component which wraps ChoicesJS library using StencilJS",
3+
"version": "1.5.1",
4+
"description": "Select and multi-select Web Component using ChoicesJS library as core",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/adidas/choicesjs-stencil.git"
@@ -21,7 +21,7 @@
2121
"build": "npm run build:min",
2222
"build:dev": "stencil build --dev --watch",
2323
"build:min": "stencil build",
24-
"copy:example": "copy ./index.html dist/* dist/**/* example",
24+
"example": "copy ./index.html assets/* dist/* dist/**/* example",
2525
"doc": "typedoc --mode file --readme ./README.md --out ./docs ./src",
2626
"lint": "npm run lint:src && npm run lint:test",
2727
"lint:src": "tslint --config ./tslint.json --project ./tsconfig.json",

0 commit comments

Comments
 (0)