-
Notifications
You must be signed in to change notification settings - Fork 144
Pills and tooltips in product step of OBW #4707
Changes from 3 commits
587d75c
8d89a01
5594dbe
6156c3f
0fe3e6d
621c72f
73731a3
ebb71a6
49d66ae
38ccaa0
ebdb24e
af62eec
3e053a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { Component, Fragment } from '@wordpress/element'; | ||
import { compose } from '@wordpress/compose'; | ||
import { Button, CheckboxControl } from '@wordpress/components'; | ||
import { Button, CheckboxControl, Tooltip } from '@wordpress/components'; | ||
import { includes, filter, get } from 'lodash'; | ||
import interpolateComponents from 'interpolate-components'; | ||
import { withDispatch, withSelect } from '@wordpress/data'; | ||
|
@@ -13,13 +13,35 @@ import { withDispatch, withSelect } from '@wordpress/data'; | |
* WooCommerce dependencies | ||
*/ | ||
import { getSetting } from '@woocommerce/wc-admin-settings'; | ||
import { H, Card, Link } from '@woocommerce/components'; | ||
import { H, Card, Link, Pill } from '@woocommerce/components'; | ||
import { ONBOARDING_STORE_NAME } from '@woocommerce/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { recordEvent } from 'lib/tracks'; | ||
import './product-types.scss'; | ||
|
||
function getLabel( description, yearlyPrice ) { | ||
if ( ! yearlyPrice ) { | ||
return description; | ||
} | ||
|
||
const monthlyPrice = ( yearlyPrice / 12.0 ).toFixed( 2 ); | ||
const priceDescription = sprintf( | ||
'$%f per month, billed annually', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we missed a translation wrapper on this text. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops, I thought that since |
||
monthlyPrice | ||
); | ||
|
||
return ( | ||
<Fragment> | ||
{ description } | ||
<Tooltip text={ __( 'This product type requires a paid extension. We\'ll add this to a cart so that you can purchase and install it later.', 'woocommerce-admin' ) }> | ||
<Pill>{ priceDescription }</Pill> | ||
</Tooltip> | ||
</Fragment> | ||
); | ||
} | ||
|
||
class ProductTypes extends Component { | ||
constructor( props ) { | ||
|
@@ -106,8 +128,9 @@ class ProductTypes extends Component { | |
render() { | ||
const { productTypes = {} } = getSetting( 'onboarding', {} ); | ||
const { error, selected } = this.state; | ||
|
||
return ( | ||
<Fragment> | ||
<div className="woocommerce-profile-wizard__product-types"> | ||
<H className="woocommerce-profile-wizard__header-title"> | ||
{ __( | ||
'What type of products will be listed?', | ||
|
@@ -119,6 +142,10 @@ class ProductTypes extends Component { | |
<Card> | ||
<div className="woocommerce-profile-wizard__checkbox-group"> | ||
{ Object.keys( productTypes ).map( ( slug ) => { | ||
const label = getLabel( | ||
productTypes[ slug ].label, | ||
productTypes[ slug ].yearly_price | ||
); | ||
const helpText = | ||
productTypes[ slug ].description && | ||
interpolateComponents( { | ||
|
@@ -155,7 +182,7 @@ class ProductTypes extends Component { | |
return ( | ||
<CheckboxControl | ||
key={ slug } | ||
label={ productTypes[ slug ].label } | ||
label={ label } | ||
help={ helpText } | ||
onChange={ () => this.onChange( slug ) } | ||
checked={ selected.includes( slug ) } | ||
|
@@ -178,7 +205,7 @@ class ProductTypes extends Component { | |
{ __( 'Continue', 'woocommerce-admin' ) } | ||
</Button> | ||
</Card> | ||
</Fragment> | ||
</div> | ||
); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.woocommerce-profile-wizard__product-types { | ||
.woocommerce-pill { | ||
border-color: $studio-woocommerce-purple-50; | ||
color: $studio-woocommerce-purple-50; | ||
margin-left: 12px; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,7 +263,7 @@ | |
} | ||
|
||
label.components-checkbox-control__label { | ||
margin-left: $gap-large - $gap-smallest; | ||
margin-left: $gap; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a small tweak to get the label to line up with the description per the design mockup |
||
} | ||
|
||
.components-base-control__help { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Pill | ||
|
||
Use `Pill` to display a pill element containing child content. | ||
|
||
## Usage | ||
|
||
```jsx | ||
<Pill>Content</Pill> | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Pill } from '@woocommerce/components'; | ||
|
||
export default () => { | ||
return ( | ||
<Pill>Content</Pill> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Pill as default } from './pill'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function Pill( { children } ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new component is born 🎉 - can we also get a line added to the changelog about this new component? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 0fe3e6d |
||
return ( | ||
<span className="woocommerce-pill"> | ||
{ children } | ||
</span> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import Pill from '../'; | ||
|
||
export default { | ||
title: 'WooCommerce Admin/components/Pill', | ||
component: Pill, | ||
} | ||
|
||
export function Default() { | ||
return ( | ||
<Pill>Content</Pill> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.woocommerce-pill { | ||
border: 1px solid $studio-gray-5; | ||
border-radius: 28px; | ||
color: $studio-gray-5; | ||
display: inline-block; | ||
font-size: 12px; | ||
padding: 1px 10px; | ||
} |
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.
TIL
toFixed
😄