使用React Stripe Elements时如何在我的Card元素中添加自定义字体?

Sia*_*Sia 4 stripe-payments reactjs react-stripe-elements

我正在使用react-stripe-elements,但自述文件并未解释如何添加自定义字体。

我有一个容器:

  <StripeProvider apiKey={stripePubkey}>
    <Elements>
      <Checkout {...this.props} />
    </Elements>
  </StripeProvider>
Run Code Online (Sandbox Code Playgroud)

然后在我的Checkout中,我有一个包装信用卡输入:

<form id="payment-form" onSubmit={this.onSubmit}>
   <CreditCardInput />
</form>
Run Code Online (Sandbox Code Playgroud)

然后我的包装信用卡输入是:

  <label>
    Card info
    <CardElement onChange={this.onCardChange} style={style} />
    <div id="card-errors" role="alert">{this.state.error.message}</div>
  </label>
Run Code Online (Sandbox Code Playgroud)

传递给的样式<CardElement />

const style = {
  base: {
    color: '#232e35',
    fontFamily: '"Podkova", "Courier New", serif',
    fontSize: '16px',
    '::placeholder': {
      color: '#9ab4b0'
    }
  },
  invalid: {
    color: '#cf3100',
    iconColor: '#cf3100'
  }
};
Run Code Online (Sandbox Code Playgroud)

Sia*_*Sia 5

事实证明,stripe.elements([options])Stripe API映射到<Elements />react-stripe-elements中的组件。因此,您可以像这样将您添加cssSrcfonts选项/属性中:

  render() {
    const fonts = [{ cssSrc: "https://fonts.googleapis.com/css?family=Podkova:400" }]

    return (
      <StripeProvider apiKey={stripePubkey}>
        <Elements fonts={fonts}>
          <Checkout {...this.props} />
        </Elements>
      </StripeProvider>
    )
  }
Run Code Online (Sandbox Code Playgroud)