|
| 1 | +import type { Meta, StoryObj } from '@storybook/html'; |
| 2 | + |
| 3 | +export default { |
| 4 | + title: 'Components/Buttons', |
| 5 | + |
| 6 | +} satisfies Meta; |
| 7 | + |
| 8 | + |
| 9 | +const BTN_SIZES = { |
| 10 | + 'Small': ['btn-small'], |
| 11 | + 'Small disabled': ['btn-small', 'disabled'], |
| 12 | + 'Normal': [], |
| 13 | + 'Normal disabled': ['disabled'], |
| 14 | + 'Large': ['btn-large'], |
| 15 | + 'Large disabled': ['btn-large', 'disabled'], |
| 16 | +}; |
| 17 | + |
| 18 | +const BTN_STYLES = { |
| 19 | + 'Default': [], // uncomment this to see the default button when no filled/tonal/outlined/text is set |
| 20 | + 'Filled': ['filled'], |
| 21 | + 'Tonal': ['tonal'], |
| 22 | + 'Outlined': ['outlined'], |
| 23 | + 'Text': ['text'] |
| 24 | +}; |
| 25 | + |
| 26 | + |
| 27 | +export const Basic: StoryObj = { |
| 28 | + render(args) { |
| 29 | + const table = document.createElement('table'); |
| 30 | + const headerRow = table.insertRow(); |
| 31 | + headerRow.insertCell(); |
| 32 | + for (const size in BTN_SIZES) { |
| 33 | + const cell = headerRow.insertCell(); |
| 34 | + cell.innerText = size; |
| 35 | + } |
| 36 | + for (const btnStype in BTN_STYLES) { |
| 37 | + const row = table.insertRow(); |
| 38 | + const cell = row.insertCell(); |
| 39 | + cell.innerText = btnStype; |
| 40 | + for (const size in BTN_SIZES) { |
| 41 | + const cell = row.insertCell(); |
| 42 | + const classes = [...BTN_STYLES[btnStype], ...BTN_SIZES[size], ...args.classes?? [] ]; |
| 43 | + const disabled = classes.includes('disabled') ? 'disabled="disabled"' : ''; |
| 44 | + let iconHtml = ''; |
| 45 | + if (args.icon) { |
| 46 | + iconHtml = `<i class="material-icons">${args.icon}</i>`; |
| 47 | + } else if (args.iconLeft) { |
| 48 | + classes.push('icon-left'); |
| 49 | + iconHtml = `<i class="material-icons">${args.iconLeft}</i>`; |
| 50 | + } else if (args.iconRight) { |
| 51 | + classes.push('icon-right'); |
| 52 | + iconHtml = `<i class="material-icons">${args.iconRight}</i>`; |
| 53 | + } |
| 54 | + // TODO - why is anchor tag used in docs rather than button tag? |
| 55 | + cell.innerHTML = ` |
| 56 | + <button ${disabled} class="${classes.join(' ')}"> |
| 57 | + ${args.label}${iconHtml} |
| 58 | + </button> |
| 59 | + `; |
| 60 | + } |
| 61 | + } |
| 62 | + return table; |
| 63 | + }, |
| 64 | + args: { |
| 65 | + label: 'Button', |
| 66 | + classes: ['btn'] |
| 67 | + } |
| 68 | +}; |
| 69 | + |
| 70 | +export const Elevated: StoryObj = { |
| 71 | + ...Basic, |
| 72 | + args: { |
| 73 | + label: 'Button', |
| 74 | + classes: ['btn', 'elevated'] |
| 75 | + } |
| 76 | +}; |
| 77 | + |
| 78 | +export const FloatingWithText: StoryObj = { |
| 79 | + ...Basic, |
| 80 | + args: { |
| 81 | + label: 'B', |
| 82 | + classes: ['btn-floating'] |
| 83 | + } |
| 84 | +}; |
| 85 | + |
| 86 | +export const FloatingWithIcon: StoryObj = { |
| 87 | + ...Basic, |
| 88 | + args: { |
| 89 | + label: '', |
| 90 | + icon: 'edit', |
| 91 | + classes: ['btn-floating'] |
| 92 | + } |
| 93 | +}; |
| 94 | + |
| 95 | +export const IconLeft: StoryObj = { |
| 96 | + ...Basic, |
| 97 | + args: { |
| 98 | + label: 'Button', |
| 99 | + iconLeft: 'cloud', |
| 100 | + classes: ['btn'] |
| 101 | + } |
| 102 | +}; |
| 103 | + |
| 104 | +export const IconRight: StoryObj = { |
| 105 | + ...Basic, |
| 106 | + args: { |
| 107 | + label: 'Submit', |
| 108 | + iconRight: 'send', |
| 109 | + classes: ['btn'] |
| 110 | + |
| 111 | + } |
| 112 | +}; |
| 113 | + |
| 114 | + |
| 115 | +export const FloatingActionButton: StoryObj = { |
| 116 | + render() { |
| 117 | + return ` |
| 118 | +<div class="fixed-action-btn"> |
| 119 | + <a class="btn-floating btn-large red"> |
| 120 | + <i class="large material-icons">mode_edit</i> |
| 121 | + </a> |
| 122 | + <ul> |
| 123 | + <li><a class="btn-floating red"><i class="material-icons">insert_chart</i></a></li> |
| 124 | + <li><a class="btn-floating yellow darken-1"><i class="material-icons">format_quote</i></a></li> |
| 125 | + <li><a class="btn-floating green"><i class="material-icons">publish</i></a></li> |
| 126 | + <li><a class="btn-floating blue"><i class="material-icons">attach_file</i></a></li> |
| 127 | + </ul> |
| 128 | +</div> |
| 129 | +
|
| 130 | +<div class="fixed-action-btn horizontal"> |
| 131 | + <a class="btn-floating btn-large red"> |
| 132 | + <i class="large material-icons">mode_edit</i> |
| 133 | + </a> |
| 134 | + <ul> |
| 135 | + <li><a class="btn-floating red"><i class="material-icons">insert_chart</i></a></li> |
| 136 | + <li><a class="btn-floating yellow darken-1"><i class="material-icons">format_quote</i></a></li> |
| 137 | + <li><a class="btn-floating green"><i class="material-icons">publish</i></a></li> |
| 138 | + <li><a class="btn-floating blue"><i class="material-icons">attach_file</i></a></li> |
| 139 | + </ul> |
| 140 | +</div> |
| 141 | +
|
| 142 | +<div class="fixed-action-btn click-to-toggle"> |
| 143 | + <a class="btn-floating btn-large red"> |
| 144 | + <i class="large material-icons">mode_edit</i> |
| 145 | + </a> |
| 146 | + <ul> |
| 147 | + <li><a class="btn-floating red"><i class="material-icons">insert_chart</i></a></li> |
| 148 | + <li><a class="btn-floating yellow darken-1"><i class="material-icons">format_quote</i></a></li> |
| 149 | + <li><a class="btn-floating green"><i class="material-icons">publish</i></a></li> |
| 150 | + <li><a class="btn-floating blue"><i class="material-icons">attach_file</i></a></li> |
| 151 | + </ul> |
| 152 | +</div> |
| 153 | + `; |
| 154 | + }, |
| 155 | +} |
0 commit comments