Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

feat: disable CreditCardSubmitButton #99

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions docs/components/CreditCardSubmitButton.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
id:CreditCardSubmitButton
title:CreditCardSubmitButton
---

Renders a button that will create a card nonce using Square's SqPaymentForm JS library and calls
`onCardNonceResponseReceived` afterwards.

When accepting credit card payments, you **must** have this component inside your `SquarePaymentForm`.

## Props
|Name|Type|Description|Default Value|
|---|---|---|---|
|children|React.ReactNode|Input field label||

| Name | Type | Description | Default Value |
| -------- | --------------- | ------------------- | ------------- |
| children | React.ReactNode | children components | |
| disabled | Boolean | disable button | false |
9 changes: 7 additions & 2 deletions src/components/CreditCardSubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import React, { useContext } from 'react';
import Context from './Context';

interface Props {
/** Input field label */
children?: React.ReactNode;
disabled?: boolean;
}

/**
* Renders a button that will create a card nonce using Square's SqPaymentForm JS library and calls
* `onCardNonceResponseReceived` afterwards.
Expand All @@ -15,8 +16,12 @@ interface Props {
export const CreditCardSubmitButton: React.FC<Props> = (props: Props) => {
const context = useContext(Context);
return (
<button className="sq-creditcard" onClick={context.onCreateNonce}>
<button disabled={props.disabled} className="sq-creditcard" onClick={context.onCreateNonce}>
{props.children ? props.children : 'Pay'}
</button>
);
};

CreditCardSubmitButton.defaultProps = {
disabled: false,
};
12 changes: 12 additions & 0 deletions src/components/__tests__/CreditCardSubmitButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ describe('CreditCardPostalCodeInput', () => {
expect(wrapper.find('button').text()).to.eql(test);
});
});

describe('disabled', () => {
it('should not be disabled by default', () => {
const wrapper = mount(<CreditCardSubmitButton />);
expect(wrapper.find('button').prop('disabled')).to.eql(false);
});

it('can be disabled', () => {
const wrapper = mount(<CreditCardSubmitButton disabled />);
expect(wrapper.find('button').prop('disabled')).to.eql(true);
});
});
});