This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: EC component Tag #17
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b34bb7d
Initial commit for EC Tag
d10a678
Merge branch 'master' into ec-component-tag
5b0e42a
Fix some bugs
33ee443
Update package.json
4d26b79
Update test snapshot
1ce6556
Merge branch 'master' into ec-component-tag
069ce05
Update package.json, tests and docs fixed
e9bb153
Update package.json
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.story.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# ECL Twig - EC Tag component |
28 changes: 28 additions & 0 deletions
28
src/ec/packages/ec-component-tag/__snapshots__/tag.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EC - Tag Button - button tag renders correctly 1`] = ` | ||
"<button class=\\"ecl-tag\\" type=\\"button\\">Button tag</button> | ||
" | ||
`; | ||
|
||
exports[`EC - Tag Link - link tag renders correctly 1`] = ` | ||
"<a href=\\"/example-path\\" class=\\"ecl-tag\\"> Link tag </a> | ||
" | ||
`; | ||
|
||
exports[`EC - Tag Removable - removable tag renders correctly 1`] = ` | ||
"<button class=\\"ecl-tag ecl-tag--removable\\" type=\\"button\\"> | ||
Removable tag | ||
|
||
<span class=\\"ecl-tag__icon\\"> | ||
<svg class=\\"ecl-icon ecl-icon--xs ecl-tag__icon-close\\"> | ||
<use xlink:href=\\"static/icons.svg#ui--close\\"></use> | ||
</svg> | ||
|
||
<svg class=\\"ecl-icon ecl-icon--xs ecl-tag__icon-close-filled\\"> | ||
<use xlink:href=\\"static/icons.svg#ui--close-filled\\"></use> | ||
</svg> | ||
</span> | ||
</button> | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# ECL Twig - EC Tag component | ||
|
||
npm package: `@ecl-twig/ec-component-tag` | ||
|
||
```shell | ||
npm install --save @ecl-twig/ec-component-tag | ||
``` | ||
|
||
## Tag | ||
|
||
### Parameters | ||
|
||
- "tag" (associative array) (default: 'predefined structure below') | ||
- "path" (string) (default: '') - path/url for tag (if needed - only for type 'link') | ||
- "type" (string) (default: '') - type of tag (can be 'link', 'button', 'removable') | ||
- "label" (string) (default: '') - tag label | ||
- "default_icon_path" (string) (default: '') - path for the icon image (need to render Icon component if tag is removable) | ||
- "extra_classes" (optional) (string) (default: '') Extra classes (space separated) for the icon | ||
- "extra_attributes" (optional) (array) (default: []) Extra attributes for icon | ||
- "name" (string) Attribute name, eg. 'data-test' | ||
- "value" (string) Attribute value, eg: 'data-test-1' | ||
|
||
### Example: | ||
|
||
```twig | ||
{% include 'path/to/tag.html.twig' with { | ||
tag: { | ||
type: 'removable', | ||
path: '/example', | ||
label: 'Tag 1' | ||
}, | ||
default_icon_path: '/static/media/icons.cbfd6efe.svg', | ||
extra_classes: 'my-extra-class-1 my-extra-class-2', | ||
extra_attributes: [{ name: 'data-test', value: 'data-test-value' },{ name: 'data-test-1', value: 'data-test-value-1' }] | ||
} %} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@ecl-twig/ec-component-tag", | ||
"author": "European Commission", | ||
"license": "EUPL-1.1", | ||
"version": "0.0.1-alpha", | ||
"description": "ECL Twig - EC Tag", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{# | ||
Parameters: | ||
- "tag" (associative array) (default: predefined structure): format: | ||
{ | ||
type: 'link' (can be 'link', 'button', 'removable'), | ||
path: '' (tag url if needed), | ||
label: '' (tag text as string) | ||
} | ||
- "default_icon_path" (string) Default path for icon tag (need to render Icon component) | ||
- "extra_classes" (string) (default: '') | ||
- "extra_attributes" (array) (default: []): format: [ | ||
{ | ||
"name" (string) (default: ''), | ||
"value" (string) (default: '') | ||
}, | ||
... | ||
] | ||
#} | ||
|
||
{# Internal properties #} | ||
{% set _tag={ | ||
type: 'link', | ||
path: '', | ||
label: '' | ||
} %} | ||
|
||
{% if tag is defined %} | ||
{% set _tag=_tag|merge(tag) %} | ||
{% endif %} | ||
|
||
{% set _css_class = 'ecl-tag' %} | ||
{% set _extra_attributes = '' %} | ||
|
||
{# Add extra class for removable tag #} | ||
{% if _tag.type == 'removable' %} | ||
{% set _css_class=_css_class~' ecl-tag--removable' %} | ||
{% endif %} | ||
|
||
{# 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 %} | ||
|
||
{# Print the result #} | ||
{% if _tag.type!='link' %} | ||
<button class="{{ _css_class }}" type="button"{{ _extra_attributes|raw }}> | ||
{{ _tag.label }} | ||
{% if _tag.type=='removable' %} | ||
<span class="ecl-tag__icon"> | ||
{% include '../ec-component-icon/icon.html.twig' with { icon: { type: 'ui', name: 'close', size: 'xs', path: default_icon_path }, extra_classes: 'ecl-tag__icon-close' } %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We recently added the extra attribute There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 069ce05 |
||
{% include '../ec-component-icon/icon.html.twig' with { icon: { type: 'ui', name: 'close-filled', size: 'xs', path: default_icon_path }, extra_classes: 'ecl-tag__icon-close-filled' } %} | ||
</span> | ||
{% endif %} | ||
</button> | ||
{% else %} | ||
<a href="{{ _tag.path }}" class="{{ _css_class }}"{{ _extra_attributes|raw }}> | ||
{{ _tag.label }} | ||
</a> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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 tagDocs from './docs/tag.md'; | ||
|
||
import tag from './tag.html.twig'; | ||
|
||
storiesOf('Components/Tag', module) | ||
.addDecorator(withKnobs) | ||
.addDecorator(withNotes) | ||
.addDecorator(withCode) | ||
.add( | ||
'as a link', | ||
() => | ||
tag({ | ||
tag: { | ||
label: text('Label', 'Link tag'), | ||
path: text('Url', '/example'), | ||
}, | ||
}), | ||
{ | ||
notes: { markdown: tagDocs }, | ||
} | ||
) | ||
.add( | ||
'as a button', | ||
() => | ||
tag({ | ||
tag: { | ||
label: text('Label', 'Button tag'), | ||
type: 'button', | ||
}, | ||
}), | ||
{ | ||
notes: { markdown: tagDocs }, | ||
} | ||
) | ||
.add( | ||
'removable', | ||
() => | ||
tag({ | ||
tag: { | ||
label: text('Label', 'Removable tag'), | ||
type: 'removable', | ||
}, | ||
default_icon_path: defaultSprite, | ||
}), | ||
{ | ||
notes: { markdown: tagDocs }, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import path from 'path'; | ||
import { renderTwigFile } from '@ecl-twig/test-utils'; | ||
|
||
describe('EC - Tag', () => { | ||
const template = path.resolve(__dirname, './tag.html.twig'); | ||
const defaultIconPath = 'static/icons.svg'; | ||
const defaultDataStructure = { | ||
tag: { | ||
path: '', | ||
type: '', | ||
label: '', | ||
}, | ||
default_icon_path: defaultIconPath, | ||
}; | ||
|
||
describe('Link', () => { | ||
test(`- link tag renders correctly`, done => { | ||
expect.assertions(1); | ||
|
||
defaultDataStructure.tag.type = 'link'; | ||
defaultDataStructure.tag.label = 'Link tag'; | ||
defaultDataStructure.tag.path = '/example-path'; | ||
|
||
renderTwigFile(template, defaultDataStructure, (err, html) => { | ||
expect(html).toMatchSnapshot(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Button', () => { | ||
test(`- button tag renders correctly`, done => { | ||
expect.assertions(1); | ||
|
||
defaultDataStructure.tag.type = 'button'; | ||
defaultDataStructure.tag.label = 'Button tag'; | ||
|
||
renderTwigFile(template, defaultDataStructure, (err, html) => { | ||
expect(html).toMatchSnapshot(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Removable', () => { | ||
test(`- removable tag renders correctly`, done => { | ||
expect.assertions(1); | ||
|
||
defaultDataStructure.tag.type = 'removable'; | ||
defaultDataStructure.tag.label = 'Removable tag'; | ||
defaultDataStructure.default_icon_path = defaultIconPath; | ||
|
||
renderTwigFile(template, defaultDataStructure, (err, html) => { | ||
expect(html).toMatchSnapshot(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: this is tag and not icon here (and next line too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what you mean. The variable
default_icon_path
defines here the path to the file with icons, which is required for the tag typeremovable
. Do you mean to change the variable name and description or define this path in the structure of the tag object. e.g.tag: { type: 'removable', icon_path: '/pathtoicon' }
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it's just the comment for extra_classes and extra_attributes. It should be tag instead of icon (but I agree that it is minor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I see my mistake, I will correct everything after merging with the EC Icon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 069ce05