|
| 1 | +// Copyright (C) 2025 The Android Open Source Project |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import m from 'mithril'; |
| 16 | +import {Button, ButtonVariant} from '../../../widgets/button'; |
| 17 | +import {CodeSnippet} from '../../../widgets/code_snippet'; |
| 18 | +import {Intent} from '../../../widgets/common'; |
| 19 | +import {EnumOption, renderWidgetShowcase} from '../widgets_page_utils'; |
| 20 | + |
| 21 | +export function renderButtonDemo(): m.Children { |
| 22 | + return [ |
| 23 | + m( |
| 24 | + '.pf-widget-intro', |
| 25 | + m('h1', 'Button'), |
| 26 | + m('p', [ |
| 27 | + 'A versatile button component with multiple variants, intents, and states. ', |
| 28 | + 'Supports icons, loading states, and can be grouped with other buttons.', |
| 29 | + ]), |
| 30 | + ), |
| 31 | + |
| 32 | + renderWidgetShowcase({ |
| 33 | + renderWidget: ({ |
| 34 | + label, |
| 35 | + icon, |
| 36 | + rightIcon, |
| 37 | + showAsGrid, |
| 38 | + showInlineWithText, |
| 39 | + ...rest |
| 40 | + }) => |
| 41 | + showAsGrid |
| 42 | + ? m( |
| 43 | + '', |
| 44 | + { |
| 45 | + style: { |
| 46 | + display: 'grid', |
| 47 | + gridTemplateColumns: 'auto auto auto', |
| 48 | + gap: '4px', |
| 49 | + }, |
| 50 | + }, |
| 51 | + Object.values(Intent).map((intent) => { |
| 52 | + return Object.values(ButtonVariant).map((variant) => { |
| 53 | + return m(Button, { |
| 54 | + style: { |
| 55 | + width: '80px', |
| 56 | + }, |
| 57 | + ...rest, |
| 58 | + label: variant, |
| 59 | + variant, |
| 60 | + intent, |
| 61 | + }); |
| 62 | + }); |
| 63 | + }), |
| 64 | + ) |
| 65 | + : m('', [ |
| 66 | + showInlineWithText && 'Inline ', |
| 67 | + m(Button, { |
| 68 | + icon: icon ? 'send' : undefined, |
| 69 | + rightIcon: rightIcon ? 'arrow_forward' : undefined, |
| 70 | + label: (label ? 'Button' : undefined) as string, |
| 71 | + onclick: () => console.log('button pressed'), |
| 72 | + ...rest, |
| 73 | + }), |
| 74 | + showInlineWithText && ' text', |
| 75 | + ]), |
| 76 | + initialOpts: { |
| 77 | + label: true, |
| 78 | + icon: true, |
| 79 | + rightIcon: false, |
| 80 | + disabled: false, |
| 81 | + intent: new EnumOption(Intent.None, Object.values(Intent)), |
| 82 | + active: false, |
| 83 | + compact: false, |
| 84 | + loading: false, |
| 85 | + variant: new EnumOption( |
| 86 | + ButtonVariant.Filled, |
| 87 | + Object.values(ButtonVariant), |
| 88 | + ), |
| 89 | + showAsGrid: false, |
| 90 | + showInlineWithText: false, |
| 91 | + rounded: false, |
| 92 | + }, |
| 93 | + }), |
| 94 | + |
| 95 | + m('.pf-widget-doc-section', [ |
| 96 | + m('h2', 'Basic Usage'), |
| 97 | + m('p', 'Create buttons with labels, icons, or both:'), |
| 98 | + m(CodeSnippet, { |
| 99 | + text: `// Simple button with label |
| 100 | +m(Button, { |
| 101 | + label: 'Click me', |
| 102 | + onclick: () => console.log('clicked'), |
| 103 | +}) |
| 104 | +
|
| 105 | +// Button with icon |
| 106 | +m(Button, { |
| 107 | + icon: 'send', |
| 108 | + label: 'Send', |
| 109 | + onclick: handleSend, |
| 110 | +}) |
| 111 | +
|
| 112 | +// Icon-only button |
| 113 | +m(Button, { |
| 114 | + icon: 'delete', |
| 115 | + onclick: handleDelete, |
| 116 | +})`, |
| 117 | + language: 'typescript', |
| 118 | + }), |
| 119 | + ]), |
| 120 | + |
| 121 | + m('.pf-widget-doc-section', [ |
| 122 | + m('h2', 'Variants & Intents'), |
| 123 | + m('p', 'Buttons come in multiple visual styles:'), |
| 124 | + m(CodeSnippet, { |
| 125 | + text: `// Variants |
| 126 | +m(Button, {label: 'Filled', variant: ButtonVariant.Filled}) |
| 127 | +m(Button, {label: 'Outlined', variant: ButtonVariant.Outlined}) |
| 128 | +m(Button, {label: 'Subtle', variant: ButtonVariant.Subtle}) |
| 129 | +
|
| 130 | +// Intents (colors) |
| 131 | +m(Button, {label: 'Primary', intent: Intent.Primary}) |
| 132 | +m(Button, {label: 'Danger', intent: Intent.Danger})`, |
| 133 | + language: 'typescript', |
| 134 | + }), |
| 135 | + ]), |
| 136 | + |
| 137 | + m('.pf-widget-doc-section', [ |
| 138 | + m('h2', 'Key Features'), |
| 139 | + m('ul', [ |
| 140 | + m('li', [ |
| 141 | + m('strong', 'Multiple Variants: '), |
| 142 | + 'Filled, Outlined, and Subtle styles for different visual weights', |
| 143 | + ]), |
| 144 | + m('li', [ |
| 145 | + m('strong', 'Intent Colors: '), |
| 146 | + 'Primary, Danger, and default intents for semantic meaning', |
| 147 | + ]), |
| 148 | + m('li', [ |
| 149 | + m('strong', 'Icons: '), |
| 150 | + 'Left icon, right icon, or icon-only buttons', |
| 151 | + ]), |
| 152 | + m('li', [ |
| 153 | + m('strong', 'States: '), |
| 154 | + 'Active, disabled, and loading states', |
| 155 | + ]), |
| 156 | + m('li', [ |
| 157 | + m('strong', 'Compact Mode: '), |
| 158 | + 'Smaller padding for dense UIs', |
| 159 | + ]), |
| 160 | + m('li', [ |
| 161 | + m('strong', 'Rounded: '), |
| 162 | + 'Circular icon buttons for floating actions', |
| 163 | + ]), |
| 164 | + m('li', [ |
| 165 | + m('strong', 'Button Groups: '), |
| 166 | + 'Group related buttons with ButtonGroup or SegmentedButtons', |
| 167 | + ]), |
| 168 | + ]), |
| 169 | + ]), |
| 170 | + ]; |
| 171 | +} |
0 commit comments