Skip to content

Commit

Permalink
Composite checkout: Update radio buttons (#37557)
Browse files Browse the repository at this point in the history
  • Loading branch information
fditrapani authored Nov 13, 2019
1 parent 23501ee commit f46b704
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/composite-checkout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Each payment method has the following schema:
{
id: string,
LabelComponent: component,
PaymentMethodComponent: component,
PaymentMethodComponent: ?component,
BillingContactComponent: component,
SubmitButtonComponent: component,
CheckoutWrapper: ?component,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ function validatePaymentMethods( paymentMethods ) {
function validatePaymentMethod( {
id,
LabelComponent,
PaymentMethodComponent,
BillingContactComponent,
SubmitButtonComponent,
SummaryComponent,
Expand All @@ -123,10 +122,6 @@ function validatePaymentMethod( {
BillingContactComponent,
`Invalid payment method '${ id }'; missing BillingContactComponent`
);
validateArg(
PaymentMethodComponent,
`Invalid payment method '${ id }'; missing PaymentMethodComponent`
);
validateArg(
SubmitButtonComponent,
`Invalid payment method '${ id }'; missing SubmitButtonComponent`
Expand Down
12 changes: 11 additions & 1 deletion packages/composite-checkout/src/components/radio-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function RadioButton( {
ariaLabel,
} ) {
const [ isFocused, changeFocus ] = useState( false );

return (
<RadioButtonWrapper isFocused={ isFocused } checked={ checked }>
<Radio
Expand All @@ -37,7 +38,7 @@ export default function RadioButton( {
<Label checked={ checked } htmlFor={ id }>
{ label }
</Label>
{ children }
{ children && <RadioButtonChildren checked={ checked }>{ children }</RadioButtonChildren> }
</RadioButtonWrapper>
);
}
Expand Down Expand Up @@ -128,6 +129,11 @@ const Label = styled.label`
}
`;

const RadioButtonChildren = styled.div`
height: ${getChildrenHeight};
overflow: hidden;
`;

function getBorderColor( { checked, theme } ) {
return checked ? theme.colors.highlight : theme.colors.borderColor;
}
Expand All @@ -140,6 +146,10 @@ function getRadioBorderWidth( { checked } ) {
return checked ? '5px' : '1px';
}

function getChildrenHeight( { checked } ) {
return checked ? 'auto' : '0';
}

function getGrayscaleValue( { checked } ) {
return checked ? 0 : '100%';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function createStripeMethod( {
};
}

function StripeCreditCardFields( { isActive, summary } ) {
function StripeCreditCardFields() {
const localize = useLocalize();
const theme = useTheme();
const { onFailure } = useCheckoutHandlers();
Expand Down Expand Up @@ -201,9 +201,6 @@ function StripeCreditCardFields( { isActive, summary } ) {
},
};

if ( ! isActive || summary ) {
return null;
}
if ( stripeLoadingError ) {
return <span>Error!</span>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export function createApplePayMethod( { registerStore, fetchStripeConfiguration
return {
id: 'apple-pay',
LabelComponent: ApplePayLabel,
PaymentMethodComponent: () => null,
BillingContactComponent: BillingFields,
SubmitButtonComponent: ApplePaySubmitButton,
SummaryComponent: ApplePaySummary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function createCreditCardMethod() {
return {
id: 'card',
LabelComponent: CreditCardLabel,
PaymentMethodComponent: ( { isActive } ) => ( isActive ? <CreditCardFields /> : null ),
PaymentMethodComponent: CreditCardFields,
BillingContactComponent: BillingFields,
SubmitButtonComponent: CreditCardSubmitButton,
SummaryComponent: CreditCardSummary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export function createPayPalMethod( { registerStore, makePayPalExpressRequest }
return {
id: 'paypal',
LabelComponent: PaypalLabel,
PaymentMethodComponent: () => null,
BillingContactComponent: BillingFields,
SubmitButtonComponent: PaypalSubmitButton,
SummaryComponent: () => {
Expand Down

0 comments on commit f46b704

Please sign in to comment.