Back to React Spectrum

LogicButton

packages/@adobe/react-spectrum/docs/button/LogicButton.mdx

2022-12-162.3 KB
Original Source

{/* Copyright 2020 Adobe. All rights reserved. This file is licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */}

import {Layout} from '@react-spectrum/docs'; export default Layout;

import docs from 'docs:@react-spectrum/button'; import {HeaderInfo, PropTable, PageDescription} from '@react-spectrum/docs'; import packageData from '@react-spectrum/button/package.json';

jsx
import {LogicButton} from '@react-spectrum/button';

category: Buttons keywords: [logic button]

LogicButton

<PageDescription>{docs.exports.LogicButton.description}</PageDescription>

<HeaderInfo packageData={packageData} componentNames={['LogicButton']} since="3.0.0" />

Example

tsx
<LogicButton variant="and">And</LogicButton>

Content

LogicButtons must have a variant and optionally can have a label. A visible label can be provided by passing children.

tsx
<LogicButton variant="or">Or</LogicButton>

Internationalization

In order to internationalize a LogicButton, a localized string should be passed to the children or aria-label prop.

Events

LogicButton supports user interactions via mouse, keyboard, and touch. You can handle all of these via the onPress prop.

The following example uses an onPress handler to update the variant.

tsx
function Example() {
  let [variant, setVariant] = React.useState<'and' | 'or'>('or');

  return (
    <LogicButton variant={variant} onPress={() => setVariant(variant === 'or' ? 'and' : 'or')}>{variant}</LogicButton>
  );
}

Props

<PropTable component={docs.exports.LogicButton} links={docs.links} />

Visual options

Variant

tsx
<LogicButton variant="or" marginEnd="20px">Or</LogicButton>
<LogicButton variant="and">And</LogicButton>

Disabled

tsx
<LogicButton variant="or" isDisabled>Or</LogicButton>