-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Created Crayons Button Preact component #6987
Conversation
whoops i didn't mean to approve, since it's a still draft ;p but whatever.. |
6807825
to
26fe594
Compare
@@ -46,16 +46,6 @@ Outlined.story = { | |||
name: 'outlined', | |||
}; | |||
|
|||
export const Text = () => ( |
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.
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', |
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.
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'; |
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.
Export all buttons so that they are accessible via.
import { Button } from '@crayons';
} | ||
|
||
if (disabled) { | ||
additionalClassNames += ' crayons-btn--disabled'; |
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.
Only buttons that generated <a />
tags get this CSS class.
as === 'button' ? { type: buttonType, disabled } : { href: url }; | ||
|
||
return ( | ||
<ComponentName |
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.
ComponentName
can be either button
or a
.
return additionalClassNames; | ||
} | ||
|
||
export const Button = ({ |
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.
import { defaultChildrenPropTypes } from '../../src/components/common-prop-types'; | ||
import { Button } from './Button'; | ||
|
||
export const DangerButton = ({ |
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.
import { defaultChildrenPropTypes } from '../../src/components/common-prop-types'; | ||
import { Button } from './Button'; | ||
|
||
export const OutlinedButton = ({ |
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.
import { defaultChildrenPropTypes } from '../../src/components/common-prop-types'; | ||
import { Button } from './Button'; | ||
|
||
export const SecondaryButton = ({ |
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.
@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. |
dc62782
to
e3b44e5
Compare
Lemme know if still needs help with hover/disabled. |
Looking at it now. I'll ping you if I get stuck. |
…button is rendered.
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. |
…crayons-button-preact-component
@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?
|
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 checked the disabled states, looking good!
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 |
…crayons-button-preact-component
done. |
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.
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).
&:enabled:not(&--disabled):hover, | ||
&:enabled:not(&--disabled):active, | ||
&--active:enabled:not(&--disabled) { |
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.
boolean logic FTW :D
children, | ||
variant = 'primary', | ||
as = 'button', | ||
className, | ||
icon, | ||
url, | ||
buttonType, | ||
disabled, | ||
onClick, | ||
onMouseOver, | ||
onMouseOut, | ||
onFocus, | ||
onBlur, |
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.
quite a lot of params :D
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.
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', |
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.
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
?
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.
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, |
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.
htmlElement === a
looks cool
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.
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.
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.
Great! tagName
which follows HTML conventions!
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.
Done.
@@ -0,0 +1,32 @@ | |||
import { h } from 'preact'; |
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'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?
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 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.
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.
+1 on having less code in general :-) Also ripgrep is quite fast so rg Button | rg danger
is not a big issue :D
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.
Yeah. I asked some others on our Slack, and I think I will just go with <Button variant="..." />
without the additional layer.
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.
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>
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.
So awesome: this will make building reusable button types in the feed so much easier!
What type of PR is this? (check all applicable)
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 theas
prop of the<Button />
component. I usedas
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} />
Secondary
<Button variant="secondary" {...props} />
Outlined
<Button variant="outlined" {...props} />
Danger
<Button variant="danger" {...props} />
Added tests?
Added to documentation?
[optional] Are there any post deployment tasks we need to perform?
[optional] What gif best describes this PR or how it makes you feel?