Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usage example #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,55 @@ If you're wondering, you probably don't need this.
npm install drupal-attribute
```

## Usage

Example of using `drupal-attribute` within a [Storybook](https://storybook.js.org) component, copied [from this tutorial](https://www.intracto.com/en-be/blog/integrating-storybook-drupal).

```JavaScript
export default { title: 'Blocks' };

import block from './block.twig';
import drupalAttribute from 'drupal-attribute'
import './block.css';
import './block.js';
export const default_block = () => (
block({
attributes: new drupalAttribute(),
title_attributes: new drupalAttribute(),
plugin_id: "Some plugin",
title_prefix: "",
title_suffix: "",
label: "I'm a block!",
content: "Lorem ipsum dolor sit amet.",
configuration: {
provider: "Some module"
}
})
);
```

```twig
{%
set classes = [
'block',
'block-' ~ configuration.provider|clean_class,
'block-' ~ plugin_id|clean_class,
]
%}
<div{{ attributes.addClass(classes) }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes }}>{{ label }}</h2>
{% endif %}
{{ title_suffix }}
{% block content %}
{{ content }}
{% endblock %}
</div>
```



## License

Apache-2.0 © [Eric MORAND]()
Expand All @@ -25,4 +74,4 @@ Apache-2.0 © [Eric MORAND]()
[daviddm-image]: https://david-dm.org/ericmorand/drupal-attribute.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/ericmorand/drupal-attribute
[coveralls-image]: https://coveralls.io/repos/github/ericmorand/drupal-attribute/badge.svg
[coveralls-url]: https://coveralls.io/github/ericmorand/drupal-attribute
[coveralls-url]: https://coveralls.io/github/ericmorand/drupal-attribute