Skip to content

Created Crayons Button Preact component #6987

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

Merged

Conversation

nickytonline
Copy link
Contributor

@nickytonline nickytonline commented Mar 31, 2020

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Design system buttons are now available as Preact button components. See the latest Storybook to see button components in action.

By default the <Button /> component renders as an HTML button element, <button ... />, but you can also render it as an HTML anchor element, <a ... />, via the as prop of the <Button /> component. I used as as this is what styled-components used. I basically couldn't think of a better prop name. 😄

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

Primary

<Button {...props} />

image

Secondary

<Button variant="secondary" {...props} />

image

Outlined

<Button variant="outlined" {...props} />

image

Danger

<Button variant="danger" {...props} />

image

Added tests?

  • yes
  • no, because they aren't needed
  • no, because I need help

Added to documentation?

  • docs.dev.to
  • readme
  • no documentation needed

[optional] Are there any post deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

Some cute cartoon animation saying "I like pressing buttons!"

@pr-triage pr-triage bot added the PR: draft bot applied label for PR's that are a work in progress label Mar 31, 2020
@rhymes rhymes changed the title Nickytonline/added crayons button preact component Added Crayons button Preact component Apr 1, 2020
@ludwiczakpawel
Copy link
Contributor

whoops i didn't mean to approve, since it's a still draft ;p but whatever..

@nickytonline nickytonline force-pushed the nickytonline/added-crayons-button-preact-component branch from 6807825 to 26fe594 Compare April 1, 2020 17:25
@@ -46,16 +46,6 @@ Outlined.story = {
name: 'outlined',
};

export const Text = () => (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This story for the HTML components really isn't necessary. Most buttons just have text in them.

@@ -5,7 +5,7 @@ import { Dropdown } from '@crayons';
import './dropdown-css-helper.scss';

export default {
title: 'Components/Dropdowns/JSX',
title: 'Components/Dropdowns',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Preact components, no point on adding another folder in the hierarchy for the Storybook sidebar. It makes sense for HTML components, but not JSX.

@@ -1 +1,2 @@
export * from '@crayons/Button';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Export all buttons so that they are accessible via.

import { Button } from '@crayons';

}

if (disabled) {
additionalClassNames += ' crayons-btn--disabled';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only buttons that generated <a /> tags get this CSS class.

as === 'button' ? { type: buttonType, disabled } : { href: url };

return (
<ComponentName
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ComponentName can be either button or a.

return additionalClassNames;
}

export const Button = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default settings will give us a primary button.

image

import { defaultChildrenPropTypes } from '../../src/components/common-prop-types';
import { Button } from './Button';

export const DangerButton = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

import { defaultChildrenPropTypes } from '../../src/components/common-prop-types';
import { Button } from './Button';

export const OutlinedButton = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

import { defaultChildrenPropTypes } from '../../src/components/common-prop-types';
import { Button } from './Button';

export const SecondaryButton = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

@nickytonline
Copy link
Contributor Author

@ludwiczakpawel, just a couple of outstanding things to do for buttons. I still have to write some tests and I also noticed that hover and active styles work when a button is disabled. If I get time today, I will look at this, but if not and you have time when you start your day tomorrow, it shouldn't take too long.

@nickytonline nickytonline force-pushed the nickytonline/added-crayons-button-preact-component branch from dc62782 to e3b44e5 Compare April 1, 2020 22:01
@ludwiczakpawel
Copy link
Contributor

Lemme know if still needs help with hover/disabled.

@nickytonline nickytonline requested review from rhymes and Ridhwana April 2, 2020 12:43
@nickytonline nickytonline marked this pull request as ready for review April 2, 2020 12:44
@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: draft bot applied label for PR's that are a work in progress labels Apr 2, 2020
@nickytonline
Copy link
Contributor Author

Lemme know if still needs help with hover/disabled.

Looking at it now. I'll ping you if I get stuck.

@nickytonline nickytonline requested a review from Zhao-Andy April 2, 2020 12:45
@nickytonline nickytonline changed the title [WIP] Added Crayons button Preact component Added Crayons button Preact component Apr 2, 2020
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Apr 2, 2020
@nickytonline nickytonline changed the title Added Crayons button Preact component Created Crayons Button Preact component Apr 2, 2020
@nickytonline
Copy link
Contributor Author

The code climate issues are complaining about prop types being repetitive code. This is a false negative as it's very common for prop types to become repetitive.

@nickytonline
Copy link
Contributor Author

@ludwiczakpawel, I did not add a variant for a design crayons button that is just text. It doesn't really make sense to me or is this just supposed to be a regular hyperlink?

<a href="#" class="... crayons-btn--text">Text Button label</a>

image

@nickytonline nickytonline requested review from joshpuetz and removed request for Zhao-Andy April 3, 2020 10:09
Copy link
Contributor

@ludwiczakpawel ludwiczakpawel left a comment

Choose a reason for hiding this comment

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

I checked the disabled states, looking good!

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Apr 3, 2020
@ludwiczakpawel
Copy link
Contributor

btw. while on it... maybe you could kill that hover effect we have: https://github.com/thepracticaldev/dev.to/blob/master/app/assets/stylesheets/scaffolds.scss#L68-L74 ? it's driving me crazy :D

@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Apr 3, 2020
@nickytonline
Copy link
Contributor Author

btw. while on it... maybe you could kill that hover effect we have: /app/assets/stylesheets/scaffolds.scss@master#L68-L74 ? it's driving me crazy :D

done.

Copy link
Contributor

@rhymes rhymes left a comment

Choose a reason for hiding this comment

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

Nice! Left some comments about naming and the presence of almost identical components (I know I voted for the separate components in Slack, but I didn't realize they were going to be identical :D).

Comment on lines +34 to +36
&:enabled:not(&--disabled):hover,
&:enabled:not(&--disabled):active,
&--active:enabled:not(&--disabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

boolean logic FTW :D

Comment on lines 37 to 49
children,
variant = 'primary',
as = 'button',
className,
icon,
url,
buttonType,
disabled,
onClick,
onMouseOver,
onMouseOut,
onFocus,
onBlur,
Copy link
Contributor

Choose a reason for hiding this comment

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

quite a lot of params :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are all properties of the props parameter, so technically it's one param. 😄 They are all potentially required. It's not that super uncommon. Think of an HTML element and all the potential attributes they can have. 😉

export const Button = ({
children,
variant = 'primary',
as = 'button',
Copy link
Contributor

Choose a reason for hiding this comment

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

mmm, I saw you note about using as but as I see it's immediately assigned to ComponentName as a const, what if we call it htmlElement instead of as or componentName ?

Copy link
Contributor Author

@nickytonline nickytonline Apr 3, 2020

Choose a reason for hiding this comment

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

The funny thing about JSX is a component name has to be Pascal cased. So it does look odd setting const ComponentName = as;.

variant,
className,
icon,
disabled: as === 'a' && disabled,
Copy link
Contributor

Choose a reason for hiding this comment

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

htmlElement === a looks cool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of htmlElement, it actually makes sense to call it tagName as that's what it really is, https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great! tagName which follows HTML conventions!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,32 @@
import { h } from 'preact';
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I'm sure you thought about it, but do we need these specialized files? They seem identical except for the name of the component. They all use <Button variant="VARIANT_NAME">, what if we just use Button ? And if and when we need one with lots of custom behavior, that can be added.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to go with the separate buttons mainly because I thought from a DX perspective, <DangerButton /> would be more grokkable than <Button variant="danger" />, but this is not a deal breaker for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on having less code in general :-) Also ripgrep is quite fast so rg Button | rg danger is not a big issue :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I asked some others on our Slack, and I think I will just go with <Button variant="..." /> without the additional layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now there is only the <Button /> component and you simply use the variant prop to decide what type of button you want. e.g. <Button variant="danger">DANGER!</Button>

Copy link
Contributor

@joshpuetz joshpuetz left a comment

Choose a reason for hiding this comment

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

So awesome: this will make building reusable button types in the feed so much easier!

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Apr 3, 2020
@nickytonline nickytonline merged commit d6e5808 into master Apr 3, 2020
@nickytonline nickytonline deleted the nickytonline/added-crayons-button-preact-component branch April 3, 2020 14:49
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants