woocommerce/plugins/woocommerce-blocks/assets/js/base/components/tabs/index.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { withInstanceId } from '@woocommerce/base-hocs/with-instance-id';
import classnames from 'classnames';
import { __ } from '@wordpress/i18n';
import { useTabState, Tab, TabList, TabPanel } from 'reakit/Tab';
/**
* Internal dependencies
*/
import './style.scss';
const Tabs = ( {
className,
onSelect = () => null,
tabs,
activeClass = 'is-active',
initialTabName,
ariaLabel = __( 'Tabbed Content', 'woo-gutenberg-products-block' ),
instanceId,
Implement Stripe CC and Stripe ApplePay payment methods (https://github.com/woocommerce/woocommerce-blocks/pull/1983) * Server side changes for payment method integrations Including adding a stripe class temporarily * update needed npm packages (and add some types) * updates to contexts * remove stepContent from payment config for payment methods * update payment method interface and typedefs Exposing a components property to pass along components that payment methods can use (so we keep styles consistent for them) * add apple pay and stripe cc integration and remove paypal * remove save payment checkbox from checkout block It is handled by payment methods. * Include an id prop for tabs * fix activePaymentMethod pass through on rendered payment method element also adds an id for the rendered tab * add styles for payment method fields If payment methods use these classes for their fields then the styles will get applied. It _could_ allow for consistent styling, we may have to provide design documentation for this? These are styles in cases where payment methods have to use elements provided by the gateway (eg. Stripe elements). In future iterations we could look at providing components to payment methods to use (if they aren’t restricted by the gateway). * fix rebase conflict * do a test payment request for applePay to determine if the current browser supports it * don’t console.error for stripe loading. * Fix placeholder errors in the editor * improve styling and add missing validation for inline card element * update pacakge-lock * rename payment-methods-demo folder to payment-methods-extension * expose checkbox control on payment method interface * export payment-methods-extension to it’s own asset build This allows us to more accurately demonstrate how payment extensions would hook in to the blocks. * don’t enqueue a style that doesn’t exist * add full stop to comments and remove obsolete comment blcok * fix spacing * switch `activeContent` to `content` for payment method registration config
2020-03-30 12:07:49 +00:00
id,
} ) => {
const initialTab = initialTabName
? { selectedId: `${ instanceId }-${ initialTabName }` }
: undefined;
const tabState = useTabState( initialTab );
if ( tabs.length === 0 ) {
return null;
}
return (
<div className={ classnames( 'wc-block-components-tabs', className ) }>
<TabList
{ ...tabState }
id={ id }
className={ 'wc-block-components-tabs__list' }
aria-label={ ariaLabel }
>
{ tabs.map( ( { name, title, ariaLabel: tabAriaLabel } ) => (
<Tab
{ ...tabState }
id={ `${ instanceId }-${ name }` }
manual={ true }
className={ classnames(
'wc-block-components-tabs__item',
{
[ activeClass ]:
// reakit uses the ID as the selectedId
`${ instanceId }-${ name }` ===
tabState.selectedId,
}
) }
onClick={ () => onSelect( name ) }
type="button"
key={ name }
aria-label={ tabAriaLabel }
>
<span className="wc-block-components-tabs__item-content">
{ title }
</span>
</Tab>
) ) }
</TabList>
{ tabs.map( ( { name, content } ) => (
<TabPanel
{ ...tabState }
key={ name }
id={ `${ instanceId }-${ name }-view` }
tabId={ `${ instanceId }-${ name }` }
className="wc-block-components-tabs__content"
>
{ tabState.selectedId === `${ instanceId }-${ name }` &&
content }
</TabPanel>
) ) }
</div>
);
};
export default withInstanceId( Tabs );