Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

feat: EC Search Form #28

Merged
merged 10 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ec/packages/ec-component-search-form/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.story.js
1 change: 1 addition & 0 deletions src/ec/packages/ec-component-search-form/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ECL Twig - EC Search Form
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EC - Search Form Default - search form renders correctly 1`] = `
"<form class=\\"ecl-search-form\\" role=\\"search\\">
<div class=\\"ecl-form-group ecl-form-group--text-input\\">
<input
id=\\"input-email\\"
name=\\"email\\"
type=\\"text\\"
placeholder=\\"\\"
class=\\"ecl-text-input ecl-search-form__text-input\\"
/>
</div>

<button
class=\\"ecl-button ecl-button--search ecl-search-form__button\\"
type=\\"submit\\"
>
<span class=\\"ecl-button__container\\">
<span class=\\"ecl-button__label\\">Search</span>

<svg
class=\\"ecl-icon ecl-icon--xs ecl-button__icon ecl-button__icon--after\\"
focusable=\\"false\\"
aria-hidden=\\"true\\"
>
<use xlink:href=\\"static/icons.svg#general--search\\"></use>
</svg>
</span>
</button>
</form>
"
`;
40 changes: 40 additions & 0 deletions src/ec/packages/ec-component-search-form/docs/search-form.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ECL Twig - EC Search Form

npm package: `@ecl-twig/ec-component-search-form`

```shell
npm install --save @ecl-twig/ec-component-search-form
```

## Search Form

### Parameters

- "text_input" (associative array) default: A predefined structure for EC Text Input
- "button" (associative array) default: A predefined structure for EC Button
- "extra_classes" (optional) (string) (default: '') Extra classes (space separated) for the form
- "extra_attributes" (optional) (array) (default: []) Extra attributes for the form
- "name" (string) Attribute name, eg. 'data-test'
- "value" (string) Attribute value, eg: 'data-test-1'

### Example:

```twig
{% include 'path/to/icon.html.twig' with {
text_input: {
id: 'input-search',
name: 'search',
extra_classes: 'ecl-search-form__text-input'
},
button: {
variant: 'search',
icon: {
type: 'general',
name: 'search',
path: '/path-to-the-icon-file',
},
label: 'Search',
extra_classes: 'ecl-search-form__button'
}
} %}
```
32 changes: 32 additions & 0 deletions src/ec/packages/ec-component-search-form/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@ecl-twig/ec-component-search-form",
"author": "European Commission",
"license": "EUPL-1.1",
"version": "0.0.1-alpha",
"description": "ECL Twig - EC Search Form",
"publishConfig": {
"access": "public"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as ec-component-text-input and ec-component-button are used directly in the template, they should be added to dependencies

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 72483ba

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I meant a dependency to the twig component @ecl-twig/ec-component-text-input and @ecl-twig/ec-component-button
As they are included in the twig template, if they are not present it will crash. So the dependency is to prevent that.
Also these two should probably be in dependenciesinstead of devDependencies

"dependencies": {
"@ecl-twig/ec-component-text-input": "^0.0.1-alpha" ,
"@ecl-twig/ec-component-button": "^0.0.1-alpha"
},
"devDependencies": {
"@ecl/ec-specs-search-form": "~2.1.0",
"@ecl/ec-component-search-form": "^2.1.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ec-europa/ecl-twig.git"
},
"bugs": {
"url": "https://github.com/ec-europa/ecl-twig/issues"
},
"homepage": "https://github.com/ec-europa/ecl-twig",
"keywords": [
"ecl",
"europa-component-library",
"design-system",
"twig"
]
}
37 changes: 37 additions & 0 deletions src/ec/packages/ec-component-search-form/search-form.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{#
Parameters:
- "text_input" (associative array) default: A predefined structure for EC Text Input
- "button" (associative array) default: A predefined structure for EC Button
- "extra_classes" (string) (default: '')
- "extra_attributes" (array) (default: []): format: [
{
"name" (string) (default: ''),
"value" (string) (default: '')
},
...
]
#}

{% set _css_class = ['ecl-search-form'] %}
{% set _extra_attributes = '' %}

{# Internal logic - Process properties #}
{% if extra_classes is defined and extra_classes is not empty %}
{% set _css_class = _css_class ~ ' ' ~ extra_classes %}
{% endif %}

{% if extra_attributes is defined and extra_attributes is not empty and extra_attributes is iterable %}
{% for attr in extra_attributes %}
{% set _extra_attributes = _extra_attributes ~ ' ' ~ attr.name ~ '="' ~ attr.value ~ '"' %}
{% endfor %}
{% endif %}

<form class="{{ _css_class }}" role="search"{{ _extra_attributes|raw }}>
{% if text_input is defined %}
{% include '../ec-component-text-input/text-input.html.twig' with text_input %}
{% endif %}

{% if button is defined %}
{% include '../ec-component-button/button.html.twig' with button %}
{% endif %}
</form>
40 changes: 40 additions & 0 deletions src/ec/packages/ec-component-search-form/search-form.story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { storiesOf } from '@storybook/html';
import { withKnobs, text } from '@storybook/addon-knobs';
import { withNotes } from '@ecl-twig/storybook-addon-notes';
import withCode from '@ecl-twig/storybook-addon-code';

import defaultSprite from '@ecl/ec-resources-icons/dist/sprites/icons.svg';

import searchFormDocs from './docs/search-form.md';
import searchForm from './search-form.html.twig';

storiesOf('Components/Search Form', module)
.addDecorator(withKnobs)
.addDecorator(withNotes)
.addDecorator(withCode)
.add(
'default',
() =>
searchForm({
text_input: {
id: 'input-search',
name: 'search',
extra_classes: 'ecl-search-form__text-input',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a (hidden) label for the text input. Even if it is not displayed to the users, it offers better accessibility (for screen reader for instance)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if I added it well in 72483ba

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a label key in your text_input object:

text_input: {
...
  label: 'Search',
...
}

hide_label: true,
label: text('Button label', 'Search'),
},
button: {
variant: 'search',
icon: {
type: 'general',
name: 'search',
path: defaultSprite,
},
label: text('Button label', 'Search'),
extra_classes: 'ecl-search-form__button',
},
}),
{
notes: { markdown: searchFormDocs },
}
);
36 changes: 36 additions & 0 deletions src/ec/packages/ec-component-search-form/search-form.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import path from 'path';
import { renderTwigFile } from '@ecl-twig/test-utils';

describe('EC - Search Form', () => {
const template = path.resolve(__dirname, './search-form.html.twig');
const defaultIconPath = 'static/icons.svg';

describe('Default', () => {
test(`- search form renders correctly`, done => {
expect.assertions(1);

const defaultDataStructure = {
text_input: {
id: 'input-email',
name: 'email',
extra_classes: 'ecl-search-form__text-input',
},
button: {
variant: 'search',
icon: {
type: 'general',
name: 'search',
path: defaultIconPath,
},
label: 'Search',
extra_classes: 'ecl-search-form__button',
},
};

renderTwigFile(template, defaultDataStructure, (err, html) => {
expect(html).toMatchSnapshot();
done();
});
});
});
});
50 changes: 50 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,19 @@
resolved "https://registry.yarnpkg.com/@ecl/ec-base/-/ec-base-2.1.0.tgz#a5f4ff88417563195045d66ed0cc8bb1f6ab0da1"
integrity sha512-VAymf9N9+afEPuErE0ABg5sH96+maUYqHCnYElaTCpjj/EAu7PeybU57k1rnlOXkXjnzEGmrqODC8Hu7XXXZJA==

"@ecl/ec-base@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ecl/ec-base/-/ec-base-2.1.1.tgz#7dcb382ebe55d19511a2a112d8603111c334db6b"
integrity sha512-q+IXLQcoumzdO/pHlX9R+JPtqYjiZYKZkLVzxTHZx+9L/UR4pRZo9aN3nKBgm78YzoeP137KRrItKZ7qgl1TaQ==

"@ecl/ec-component-button@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ecl/ec-component-button/-/ec-component-button-2.1.1.tgz#7ea70e9e4c8b1744831ac33ad0e0c9d5cce521d4"
integrity sha512-5w4EIsLLwklr6GEvP9S4wVHs1HPFnFAfzmXaDMKRXz8ok0iyPU7vvWw5FLOEutlvoCy33kALE9W3AC4Ws/W3aA==
dependencies:
"@ecl/ec-base" "^2.1.1"
"@ecl/ec-component-icon" "^2.1.1"

"@ecl/ec-component-form-feedback-message@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@ecl/ec-component-form-feedback-message/-/ec-component-form-feedback-message-2.1.0.tgz#2b885399ab9eff231a244f271fa02241d5734df5"
Expand Down Expand Up @@ -742,6 +755,31 @@
dependencies:
"@ecl/ec-base" "^2.1.0"

"@ecl/ec-component-form-text-input@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ecl/ec-component-form-text-input/-/ec-component-form-text-input-2.1.1.tgz#ef684f47103c875c73bdd976ebce11e3251ae185"
integrity sha512-izSvOKnAXlRik3qbEb5XqlvCn5CdiBn8TkoVBloIEr8FsxHd0KpZINGAs+vqLCbswSmZR04w/MEGuuobpb/0dA==
dependencies:
"@ecl/ec-base" "^2.1.1"

"@ecl/ec-component-icon@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ecl/ec-component-icon/-/ec-component-icon-2.1.1.tgz#15fbb83e5fd940c208fc05d482d12cfa51f655c2"
integrity sha512-6aUDaXCWZgdyFv9B+zix6mBADPb9OzuoPxvfsARC689zToCPYl+zcYzsFPT9b4wW3+naqRnngl9RVQUG8ksheg==
dependencies:
"@ecl/ec-base" "^2.1.1"

"@ecl/ec-component-search-form@^2.1.0":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ecl/ec-component-search-form/-/ec-component-search-form-2.1.1.tgz#b9cbbd15b3536fc083b8090cf43318cf80530bc8"
integrity sha512-Y8HmmksmjjecB6ErHQtotEPm+0cUvMvGUEvGS/c+dRYJJGzytJiKsaqyTlYzj4OD/iugpNrztuaW/WS8QDe56g==
dependencies:
"@ecl/ec-base" "^2.1.1"
"@ecl/ec-component-button" "^2.1.1"
"@ecl/ec-component-form-text-input" "^2.1.1"
"@ecl/ec-component-icon" "^2.1.1"
"@ecl/ec-utility-screen-reader" "^2.1.1"

"@ecl/ec-resources-icons@^2.1.1", "@ecl/ec-resources-icons@~2.1.0":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ecl/ec-resources-icons/-/ec-resources-icons-2.1.1.tgz#e0a034a3c9aa499d9179a137ebe02e5518033eec"
Expand Down Expand Up @@ -774,6 +812,11 @@
resolved "https://registry.yarnpkg.com/@ecl/ec-specs-link/-/ec-specs-link-2.1.1.tgz#35a576c0e9a7d7db8b862f480171b172b9e36c86"
integrity sha512-Dt1MK3S/e4neDATp6ymzYKeF1+vOoO28/stJaNPLpQHT2mOIqa2rKmvlyqU5WjF2CcUvzfBmrLw+vyPKBnkwrA==

"@ecl/ec-specs-search-form@~2.1.0":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ecl/ec-specs-search-form/-/ec-specs-search-form-2.1.1.tgz#2dce0524030efd55e823bcacc1c419381aec6d27"
integrity sha512-MpYlOXUpZ2oBx56KakpmV/ARsWEfJPM6L9tnKOU6vdPjdj3cUofklCWKB23P+Oy0v8xnWA9cjjpQKQBCTPql9A==

"@ecl/ec-specs-tag@~2.1.0":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ecl/ec-specs-tag/-/ec-specs-tag-2.1.1.tgz#2923e92b939e335387093cf75a8094fef4aa4b6a"
Expand All @@ -784,6 +827,13 @@
resolved "https://registry.yarnpkg.com/@ecl/ec-specs-text-input/-/ec-specs-text-input-2.1.0.tgz#482bd4655ea8dde8b68bffacfb21e9d0936fe73c"
integrity sha512-u/1UHaZXgDkI6BbmRQVVGleI7IM1dUc/lV23rdNy6xylMgLE0DcmMKz+gUiVilcrd8AOGgm6UVCb4T/GYQzHqA==

"@ecl/ec-utility-screen-reader@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ecl/ec-utility-screen-reader/-/ec-utility-screen-reader-2.1.1.tgz#1b3808b7e43281986c14cc2b598a7974a4fdea01"
integrity sha512-E8CARlHky++r90+92/6MY720vEt+jdhWRcTvjtcZfh8gxqxc7bIxasLOxNNibE0DNQoRxlk9pb018mfIdyeUlw==
dependencies:
"@ecl/ec-base" "^2.1.1"

"@ecl/eu-base@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@ecl/eu-base/-/eu-base-2.1.0.tgz#a2987c4d3298c2ee822d726cc1d70e91d6b81ed2"
Expand Down