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

Comment Form code example + docs + template updates #1353

Merged
merged 7 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions .changeset/poor-planes-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudfour/patterns': minor
---

Remove function call from logged_in_user object in template
gerardo-rodriguez marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 36 additions & 6 deletions src/components/comment-form/comment-form.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Story, Canvas, Meta } from '@storybook/addon-docs/blocks';
import { useEffect } from '@storybook/client-api';
import { createElasticTextArea } from '../input/elastic-textarea.ts';
import { makeTwigInclude } from '../../make-twig-include';
import template from './comment-form.twig';
const tyler = {
name: () => 'Tyler Sticka',
link: () => 'https://cloudfour.com/is/tyler',
name: 'Tyler Sticka',
link: 'https://cloudfour.com/is/tyler',
};

<Meta
Expand All @@ -26,7 +27,19 @@ const tyler = {
The form used to add a comment to an article.

<Canvas>
<Story name="Default" args={{ isReply: false }}>
<Story
name="Default"
args={{ isReply: false }}
parameters={{
docs: {
source: {
code: makeTwigInclude(
'@cloudfour/components/comment-form/comment-form.twig'
),
},
},
}}
>
{({ isLoggedIn, isReply }) => {
useEffect(() => {
const { destroy } = createElasticTextArea(
Expand All @@ -46,7 +59,20 @@ The form used to add a comment to an article.
There is also a reply version of this component (`is_reply: true`), used to reply to an existing comment:

<Canvas>
<Story name="Reply" args={{ isReply: true }}>
<Story
name="Reply"
args={{ isReply: true, isLoggedIn: true }}
parameters={{
docs: {
source: {
code: makeTwigInclude(
'@cloudfour/components/comment-form/comment-form.twig',
{ logged_in_user: tyler, log_out_url: '/logout', is_reply: true }
),
},
},
}}
>
{({ isLoggedIn, isReply }) => {
useEffect(() => {
const { destroy } = createElasticTextArea(
Expand All @@ -70,11 +96,15 @@ There is also a reply version of this component (`is_reply: true`), used to repl

```ts
{
name: () => string;
link: () => string;
name: string | () => string;
link: string | () => string;
}
```

- `log_out_url`: URL used for log out link.
- `is_reply`: Whether the comment is a reply to another comment.
- `prompt` (block): The text that is displayed above the messge box.

## JavaScript

The Comment Form component includes the [Elastic Textarea component](http://localhost:6006/?path=/docs/components-input--elastic-textarea). See the Elastic Textarea component for JavaScript setup details.
2 changes: 1 addition & 1 deletion src/components/comment-form/comment-form.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% endblock %}
{% endembed %}
{% if logged_in_user and log_out_url %}
<p>Logged in as <a href="{{ logged_in_user.link() }}">{{ logged_in_user.name() }}</a>. <a href="{{ log_out_url }}">Log out?</a></p>
<p>Logged in as <a href="{{ logged_in_user.link }}">{{ logged_in_user.name }}</a>. <a href="{{ log_out_url }}">Log out?</a></p>
{% else %}
{% embed '@cloudfour/objects/form-group/form-group.twig' with { label: 'Name', class: 'c-comment-form__name' } only %}
{% block control %}
Expand Down
2 changes: 1 addition & 1 deletion src/make-twig-include.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @param {string} path
* @param {any} args
*/
export const makeTwigInclude = (path, args) => {
export const makeTwigInclude = (path, args = {}) => {
const argsString =
Object.keys(args).length > 0
? ` with ${JSON.stringify(args, null, 2)}`
Expand Down