packages/@adobe/react-spectrum/docs/button/LogicButton.mdx
{/* 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';
import {LogicButton} from '@react-spectrum/button';
<PageDescription>{docs.exports.LogicButton.description}</PageDescription>
<HeaderInfo packageData={packageData} componentNames={['LogicButton']} since="3.0.0" />
<LogicButton variant="and">And</LogicButton>
LogicButtons must have a variant and optionally can have a label. A visible label can be provided by passing children.
<LogicButton variant="or">Or</LogicButton>
In order to internationalize a LogicButton, a localized string should be passed to the children or aria-label prop.
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.
function Example() {
let [variant, setVariant] = React.useState<'and' | 'or'>('or');
return (
<LogicButton variant={variant} onPress={() => setVariant(variant === 'or' ? 'and' : 'or')}>{variant}</LogicButton>
);
}
<LogicButton variant="or" marginEnd="20px">Or</LogicButton>
<LogicButton variant="and">And</LogicButton>
<LogicButton variant="or" isDisabled>Or</LogicButton>