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

Integrate reply Comment Form into Comment pattern #1423

Merged
merged 49 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
caa5308
Rename `demo_control`
Paul-Hebert Jul 16, 2021
d76856b
Stub out JS/Test files for comments
Paul-Hebert Jul 19, 2021
746a011
Change TS Config target to avoid incorrect warnings
Paul-Hebert Jul 19, 2021
d936a13
Fix closing tag
Paul-Hebert Jul 19, 2021
f509852
Add TS for comments
Paul-Hebert Jul 19, 2021
07dba85
Handle spacing
Paul-Hebert Jul 19, 2021
65e7b52
Add controls to docs
Paul-Hebert Jul 19, 2021
e94c3a1
Update comment generation code
Paul-Hebert Jul 19, 2021
a3c1620
Add test for comment reply form
Paul-Hebert Jul 19, 2021
eb002be
Tidy template
Paul-Hebert Jul 19, 2021
49d6f4b
Add accessible names to comment forms
Paul-Hebert Jul 19, 2021
2d9f556
Add template props docs
Paul-Hebert Jul 19, 2021
06bca63
Add missing props
Paul-Hebert Jul 20, 2021
232792c
Add code samples
Paul-Hebert Jul 20, 2021
da28af4
Handle reply heading
Paul-Hebert Jul 20, 2021
15b1bf9
Move `allow_replies` outside `comment` object
Paul-Hebert Jul 20, 2021
60468ac
Lint
Paul-Hebert Jul 20, 2021
5f8f15e
Add note about cancel button
Paul-Hebert Jul 20, 2021
06537d3
Only run JS for comments with replies enabled
Paul-Hebert Jul 20, 2021
b226ba5
Fix VoiceOver focus
Paul-Hebert Jul 20, 2021
713077e
Add focus test to comments
Paul-Hebert Jul 20, 2021
96348bc
Lint
Paul-Hebert Jul 20, 2021
cee3a46
update comment form story
Paul-Hebert Jul 20, 2021
5ef0f0c
Fix type error
Paul-Hebert Jul 20, 2021
d4952b8
Tidy
Paul-Hebert Jul 20, 2021
d159cc8
lint
Paul-Hebert Jul 20, 2021
e7dd9da
Fix function name mismatch
Paul-Hebert Jul 20, 2021
b8673a3
Another function name mismatch
Paul-Hebert Jul 20, 2021
53e1640
Remove unnecessary spread
Paul-Hebert Jul 21, 2021
3485aff
Move JS hide/show logic to CSS
Paul-Hebert Jul 21, 2021
aeb1601
Focus reply button when comment form is closed
Paul-Hebert Jul 21, 2021
5006f41
Fix iOS focus issue
Paul-Hebert Jul 21, 2021
a3b3174
Improve comment
Paul-Hebert Jul 21, 2021
a81d384
lint
Paul-Hebert Jul 21, 2021
2763ffd
Use aria-describedby
Paul-Hebert Jul 21, 2021
b5ac5c3
Make test util for loading global CSS
Paul-Hebert Jul 21, 2021
118e033
Switch JS setup to single instance method
Paul-Hebert Jul 21, 2021
b32ea26
Add cleanup methods
Paul-Hebert Jul 21, 2021
f066e31
Lint
Paul-Hebert Jul 21, 2021
ffdbad1
Fix code example
Paul-Hebert Jul 21, 2021
e163efb
Update src/components/comment-form/comment-form.stories.mdx
Paul-Hebert Jul 22, 2021
f6261a4
Fix code examples
Paul-Hebert Jul 22, 2021
bda5f72
Merge branch 'feat/integrate-reply-form' of https://github.com/cloudf…
Paul-Hebert Jul 22, 2021
fecebe2
Add changeset
Paul-Hebert Jul 22, 2021
80db9f6
Replace optional chaining with early return
Paul-Hebert Jul 22, 2021
70d4a1b
Lint
Paul-Hebert Jul 22, 2021
ea636b4
Update src/components/comment/comment.stories.mdx
Paul-Hebert Jul 22, 2021
a8a1daf
Merge remote-tracking branch 'origin/v-next' into feat/integrate-repl…
Paul-Hebert Jul 22, 2021
cf021e7
Lint
Paul-Hebert Jul 22, 2021
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
10 changes: 9 additions & 1 deletion src/components/comment-form/comment-form.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ The form used to add a comment to an article.
logged_in_user: isLoggedIn ? tyler : undefined,
log_out_url: '/logout',
is_reply: isReply,
heading_id: 'leave-a-comment',
Paul-Hebert marked this conversation as resolved.
Show resolved Hide resolved
});
}}
</Story>
</Canvas>

There is also a reply version of this component (`is_reply: true`), used to reply to an existing comment:
There is also a reply version of this component (`is_reply: true`), used to reply to an existing comment. (You'll also want to modify `heading_tag`, `heading_id`, `heading_class`, and `heading_text`. When using the [Comment pattern](/docs/components-comment--with-reply-button) this will be done automatically.)

<Canvas>
<Story
Expand Down Expand Up @@ -84,6 +85,9 @@ There is also a reply version of this component (`is_reply: true`), used to repl
logged_in_user: isLoggedIn ? tyler : undefined,
log_out_url: '/logout',
is_reply: isReply,
heading_id: 'reply-to-comment-100',
heading_tag: 'h4',
heading_text: 'Reply to John Doe',
});
}}
</Story>
Expand All @@ -92,6 +96,10 @@ There is also a reply version of this component (`is_reply: true`), used to repl
## Template Properties

- `class`: Append a class to the root element.
- `heading_id`: A unique ID for your heading element. This will be used as the accessible name for the form.
- `heading_tag`: The tag for your heading (defaults to `h2`).
- `heading_text`: The text for your heading.
- `heading_class`: An optional class for your heading.
Copy link
Member Author

Choose a reason for hiding this comment

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

I was tempted to replace this all with a heading block, but that makes it more likely for the aria-labelledby relationship between the form and heading to get messed up.

- `logged_in_user`: [user object](https://timber.github.io/docs/reference/timber-user/#properties) of the type:

```ts
Expand Down
15 changes: 11 additions & 4 deletions src/components/comment-form/comment-form.twig
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<form
class="c-comment-form{% if class %} {{class}}{% endif %}"
{% if heading_id %}aria-labelledby="{{ heading_id }}"{% endif %}
gerardo-rodriguez marked this conversation as resolved.
Show resolved Hide resolved
{%- if action %}action="{{ action }}"{% endif -%}
{%- if method %}method="{{ method }}"{% endif -%}
>
{% block prompt %}
<h2>Leave a Comment</h2>
<p>Please be kind, courteous and constructive. You may use simple HTML or <a href="https://en.support.wordpress.com/markdown-quick-reference">Markdown</a> in your comments. All fields are required.</p>
{% set _heading_tag = heading_tag|default('h2') %}
<{{_heading_tag}}
{% if heading_id %}id="{{ heading_id }}"{% endif %}
{% if heading_class %}class="{{ heading_class }}"{% endif %}
>
{{ heading_text|default("Leave a Comment") }}
</{{_heading_tag}}>
<p>Please be kind, courteous and constructive. You may use simple HTML or <a href="https://en.support.wordpress.com/markdown-quick-reference">Markdown</a> in your comments. All fields are required.</p>
{% endblock %}
{% embed '@cloudfour/objects/form-group/form-group.twig' with { label: 'Message' } only %}
{% block control %}
Expand Down Expand Up @@ -34,10 +41,10 @@
{% embed '@cloudfour/objects/button-group/button-group.twig' only %}
{% block content %}
{% include '@cloudfour/components/button/button.twig' with { label: 'Submit Reply' } only %}
{% include '@cloudfour/components/button/button.twig' with { label: 'Cancel', class: 'c-button--secondary' } only %}
{% include '@cloudfour/components/button/button.twig' with { label: 'Cancel', class: 'c-button--secondary js-cancel-reply' } only %}
{% endblock %}
{% endembed %}
{% else %}
{% include '@cloudfour/components/button/button.twig' with { label: 'Submit Comment' } only %}
{% endif %}
</div>
</form>
gerardo-rodriguez marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions src/components/comment/comment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/// Display a vertical line if the comment contains a reply thread to connect
/// those comments visually with their parent.
.c-comment.is-replying::after,
.c-comment--thread::after {
Copy link
Member Author

Choose a reason for hiding this comment

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

I added a separate class that does the same thing as --thread so our JS doesn't have to handle correctly toggling --thread and account for whether a comment already has a thread or not.

border-radius: size.$border-radius-full;
content: '';
Expand Down Expand Up @@ -124,6 +125,10 @@
// Visually centers the child avatars with the indentation of the parent
// comment. Without this, the replies feel nested too far to the right.
margin-left: math.div(size.$square-avatar-small, -2);
}

.c-comment__replies,
.c-comment__reply-form {
// Since the replies are likely wrapped in a Rhythm object intended to inherit
// the parent rhythm, we can use that custom property to inherit that same
// spacing between the meta and replies.
Expand Down
Loading