Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I put border styling with react-stripe-elements input component?

About this React component library.

  • https://github.com/stripe/react-stripe-elements

How can I put border styling with input component?

<CardElement style={{   base: {     fontSize: '18px',     border: '1px solid red' // it is not work.   }  }} /> 

but, seems they didn't provide custom style interface, though.

  • https://stripe.com/docs/elements/reference#element-options\

Anyone know?

Update:

following are sample code that using StripeElement class to apply custom styling.

.StripeElement {   border: 1px solid #eee; }  .StripeElement--invalid {   border: 1px solid red; } 
like image 975
mitsuruog Avatar asked May 15 '17 08:05

mitsuruog


People also ask

How do I add a border style in React?

Use the border css property to set the border style of an element in React, e.g. <div style={{border: '1px solid rgba(0,255,0,0.3)'}}> . If you only need to style a specific border, use the corresponding property, e.g. borderBottom .

How do you use Stripe JS in React?

Render an Elements provider at the root of your React app so that it is available everywhere you need it. To use the Elements provider, call loadStripe from @stripe/stripe-js with your publishable key. The loadStripe function asynchronously loads the Stripe. js script and initializes a Stripe object.


2 Answers

Great question! As noted here, to apply padding or a border to a Stripe element you want to style the parent DOM node that contains the element, not the element itself:

https://stripe.com/docs/elements/reference#the-element-container

I'd wrap your CardElement in a div and then apply styling to that. As noted above, Elements automatically applies the StripeElement class to the parent element, as well as complete/empty/focus/invalid states.

like image 193
hpar Avatar answered Sep 17 '22 17:09

hpar


The simplest solution is:

<div   style={     {      border: '2px solid red'     }   } > </div> 
like image 35
Jackkobec Avatar answered Sep 18 '22 17:09

Jackkobec