|
| 1 | +import { Button, including, not, HTML } from "../src"; |
| 2 | +import { Button as Component } from "@material-ui/core"; |
| 3 | +import { renderComponent } from "./helpers"; |
| 4 | +import { ComponentProps } from "react"; |
| 5 | +import { ComponentMeta, ComponentStoryObj } from "@storybook/react"; |
| 6 | + |
| 7 | +export default { |
| 8 | + title: "Button", |
| 9 | + component: renderComponent(Component, { children: "My Button" }), |
| 10 | +} as ComponentMeta<typeof Component>; |
| 11 | + |
| 12 | +const button = Button(including("My Button".toUpperCase())); |
| 13 | + |
| 14 | +export const Default: ComponentStoryObj<typeof Component> = { |
| 15 | + async play() { |
| 16 | + await button.exists(); |
| 17 | + await button.has({ text: "My Button".toUpperCase() }); |
| 18 | + await button.has({ className: including("MuiButton-root") }); |
| 19 | + await button.has({ className: including("MuiButton-text") }); |
| 20 | + await button.has({ className: not(including("MuiButton-textSecondary")) }); |
| 21 | + await button.has({ className: not(including("MuiButton-outlined")) }); |
| 22 | + await button.has({ className: not(including("MuiButton-contained")) }); |
| 23 | + }, |
| 24 | +}; |
| 25 | + |
| 26 | +export const Secondary: ComponentStoryObj<typeof Component> = { |
| 27 | + args: { color: "secondary" }, |
| 28 | + async play() { |
| 29 | + await button.has({ className: including("MuiButton-root") }); |
| 30 | + await button.has({ className: including("MuiButton-text") }); |
| 31 | + await button.has({ className: not(including("MuiButton-contained")) }); |
| 32 | + await button.has({ className: not(including("MuiButton-textPrimary")) }); |
| 33 | + }, |
| 34 | +}; |
| 35 | + |
| 36 | +export const Outlined: ComponentStoryObj<typeof Component> = { |
| 37 | + args: { variant: "outlined" }, |
| 38 | + async play() { |
| 39 | + await button.has({ className: including("MuiButton-outlined") }); |
| 40 | + await button.has({ className: not(including("MuiButton-text")) }); |
| 41 | + await button.has({ className: not(including("MuiButton-contained")) }); |
| 42 | + }, |
| 43 | +}; |
| 44 | + |
| 45 | +export const PrimaryOutlined: ComponentStoryObj<typeof Component> = { |
| 46 | + args: { variant: "outlined", color: "primary" }, |
| 47 | + async play() { |
| 48 | + await button.has({ className: including("MuiButton-outlined") }); |
| 49 | + await button.has({ className: including("MuiButton-outlinedPrimary") }); |
| 50 | + }, |
| 51 | +}; |
| 52 | + |
| 53 | +export const SecondaryOutlined: ComponentStoryObj<typeof Component> = { |
| 54 | + args: { variant: "outlined", color: "secondary" }, |
| 55 | + async play() { |
| 56 | + await button.has({ className: including("MuiButton-outlined") }); |
| 57 | + await button.has({ className: including("MuiButton-outlinedSecondary") }); |
| 58 | + }, |
| 59 | +}; |
| 60 | + |
| 61 | +export const InheritOutlined: ComponentStoryObj<typeof Component> = { |
| 62 | + args: { variant: "outlined", color: "inherit" }, |
| 63 | + async play() { |
| 64 | + await button.has({ className: including("MuiButton-root") }); |
| 65 | + await button.has({ className: including("MuiButton-outlined") }); |
| 66 | + await button.has({ className: including("MuiButton-colorInherit") }); |
| 67 | + await button.has({ className: not(including("MuiButton-text")) }); |
| 68 | + await button.has({ className: not(including("MuiButton-textSecondary")) }); |
| 69 | + await button.has({ className: not(including("MuiButton-contained")) }); |
| 70 | + }, |
| 71 | +}; |
| 72 | + |
| 73 | +export const Contained: ComponentStoryObj<typeof Component> = { |
| 74 | + args: { variant: "contained" }, |
| 75 | + async play() { |
| 76 | + await button.has({ className: including("MuiButton-root") }); |
| 77 | + await button.has({ className: including("MuiButton-contained") }); |
| 78 | + await button.has({ className: not(including("MuiButton-textPrimary")) }); |
| 79 | + await button.has({ className: not(including("MuiButton-textSecondary")) }); |
| 80 | + }, |
| 81 | +}; |
| 82 | + |
| 83 | +export const ContainedPrimary: ComponentStoryObj<typeof Component> = { |
| 84 | + args: { variant: "contained", color: "primary" }, |
| 85 | + async play() { |
| 86 | + await button.has({ className: including("MuiButton-root") }); |
| 87 | + await button.has({ className: including("MuiButton-contained") }); |
| 88 | + await button.has({ className: including("MuiButton-containedPrimary") }); |
| 89 | + await button.has({ className: not(including("MuiButton-text")) }); |
| 90 | + await button.has({ className: not(including("MuiButton-containedSecondary")) }); |
| 91 | + }, |
| 92 | +}; |
| 93 | + |
| 94 | +export const ContainedSecondary: ComponentStoryObj<typeof Component> = { |
| 95 | + args: { variant: "contained", color: "secondary" }, |
| 96 | + async play() { |
| 97 | + await button.has({ className: including("MuiButton-root") }); |
| 98 | + await button.has({ className: including("MuiButton-contained") }); |
| 99 | + await button.has({ className: including("MuiButton-containedSecondary") }); |
| 100 | + await button.has({ className: not(including("MuiButton-text")) }); |
| 101 | + await button.has({ className: not(including("MuiButton-containedPrimary")) }); |
| 102 | + }, |
| 103 | +}; |
| 104 | + |
| 105 | +export const SmallText: ComponentStoryObj<typeof Component> = { |
| 106 | + args: { size: "small" }, |
| 107 | + async play() { |
| 108 | + await button.has({ className: including("MuiButton-root") }); |
| 109 | + await button.has({ className: including("MuiButton-text") }); |
| 110 | + await button.has({ className: including("MuiButton-textSizeSmall") }); |
| 111 | + await button.has({ className: not(including("MuiButton-textSizeLarge")) }); |
| 112 | + await button.has({ className: not(including("MuiButton-outlinedSizeSmall")) }); |
| 113 | + await button.has({ className: not(including("MuiButton-outlinedSizeLarge")) }); |
| 114 | + await button.has({ className: not(including("MuiButton-containedSizeSmall")) }); |
| 115 | + await button.has({ className: not(including("MuiButton-containedSizeLarge")) }); |
| 116 | + }, |
| 117 | +}; |
| 118 | + |
| 119 | +export const LargeText: ComponentStoryObj<typeof Component> = { |
| 120 | + args: { size: "large" }, |
| 121 | + async play() { |
| 122 | + await button.has({ className: including("MuiButton-root") }); |
| 123 | + await button.has({ className: including("MuiButton-text") }); |
| 124 | + await button.has({ className: including("MuiButton-textSizeLarge") }); |
| 125 | + await button.has({ className: not(including("MuiButton-textSizeSmall")) }); |
| 126 | + await button.has({ className: not(including("MuiButton-outlinedSizeSmall")) }); |
| 127 | + await button.has({ className: not(including("MuiButton-outlinedSizeLarge")) }); |
| 128 | + await button.has({ className: not(including("MuiButton-containedSizeSmall")) }); |
| 129 | + await button.has({ className: not(including("MuiButton-containedSizeLarge")) }); |
| 130 | + }, |
| 131 | +}; |
| 132 | + |
| 133 | +export const SmallOutlined: ComponentStoryObj<typeof Component> = { |
| 134 | + args: { variant: "outlined", size: "small" }, |
| 135 | + async play() { |
| 136 | + await button.has({ className: including("MuiButton-root") }); |
| 137 | + await button.has({ className: including("MuiButton-outlined") }); |
| 138 | + await button.has({ className: including("MuiButton-outlinedSizeSmall") }); |
| 139 | + await button.has({ className: not(including("MuiButton-textSizeSmall")) }); |
| 140 | + await button.has({ className: not(including("MuiButton-outlinedSizeLarge")) }); |
| 141 | + await button.has({ className: not(including("MuiButton-containedSizeSmall")) }); |
| 142 | + await button.has({ className: not(including("MuiButton-containedSizeLarge")) }); |
| 143 | + }, |
| 144 | +}; |
| 145 | + |
| 146 | +export const LargeOutlined: ComponentStoryObj<typeof Component> = { |
| 147 | + args: { variant: "outlined", size: "large" }, |
| 148 | + async play() { |
| 149 | + await button.has({ className: including("MuiButton-root") }); |
| 150 | + await button.has({ className: including("MuiButton-outlined") }); |
| 151 | + await button.has({ className: including("MuiButton-outlinedSizeLarge") }); |
| 152 | + await button.has({ className: not(including("MuiButton-textSizeSmall")) }); |
| 153 | + await button.has({ className: not(including("MuiButton-textSizeLarge")) }); |
| 154 | + await button.has({ className: not(including("MuiButton-outlinedSizeSmall")) }); |
| 155 | + await button.has({ className: not(including("MuiButton-containedSizeLarge")) }); |
| 156 | + await button.has({ className: not(including("MuiButton-containedSizeSmall")) }); |
| 157 | + }, |
| 158 | +}; |
| 159 | + |
| 160 | +export const SmallContained: ComponentStoryObj<typeof Component> = { |
| 161 | + args: { variant: "contained", size: "small" }, |
| 162 | + async play() { |
| 163 | + await button.has({ className: including("MuiButton-root") }); |
| 164 | + await button.has({ className: including("MuiButton-contained") }); |
| 165 | + await button.has({ className: including("MuiButton-containedSizeSmall") }); |
| 166 | + await button.has({ className: not(including("MuiButton-textSizeSmall")) }); |
| 167 | + await button.has({ className: not(including("MuiButton-textSizeLarge")) }); |
| 168 | + await button.has({ className: not(including("MuiButton-outlinedSizeSmall")) }); |
| 169 | + await button.has({ className: not(including("MuiButton-outlinedSizeLarge")) }); |
| 170 | + await button.has({ className: not(including("MuiButton-containedSizeLarge")) }); |
| 171 | + }, |
| 172 | +}; |
| 173 | + |
| 174 | +export const LargeContained: ComponentStoryObj<typeof Component> = { |
| 175 | + args: { variant: "contained", size: "large" }, |
| 176 | + async play() { |
| 177 | + await button.has({ className: including("MuiButton-root") }); |
| 178 | + await button.has({ className: including("MuiButton-contained") }); |
| 179 | + await button.has({ className: including("MuiButton-containedSizeLarge") }); |
| 180 | + await button.has({ className: not(including("MuiButton-textSizeSmall")) }); |
| 181 | + await button.has({ className: not(including("MuiButton-textSizeLarge")) }); |
| 182 | + await button.has({ className: not(including("MuiButton-outlinedSizeSmall")) }); |
| 183 | + await button.has({ className: not(including("MuiButton-outlinedSizeLarge")) }); |
| 184 | + await button.has({ className: not(including("MuiButton-containedSizeSmall")) }); |
| 185 | + }, |
| 186 | +}; |
| 187 | + |
| 188 | +export const StartIcon: ComponentStoryObj<typeof Component> = { |
| 189 | + args: { startIcon: <span>icon</span> }, |
| 190 | + async play() { |
| 191 | + await button.has({ className: including("MuiButton-root") }); |
| 192 | + await button.has({ className: including("MuiButton-text") }); |
| 193 | + await button.find(HTML({ className: including("MuiButton-startIcon") })).exists(); |
| 194 | + await button.find(HTML({ className: not(including("MuiButton-endIcon")) })).exists(); |
| 195 | + }, |
| 196 | +}; |
| 197 | + |
| 198 | +export const EndIcon: ComponentStoryObj<typeof Component> = { |
| 199 | + args: { endIcon: <span>icon</span> }, |
| 200 | + async play() { |
| 201 | + await button.has({ className: including("MuiButton-root") }); |
| 202 | + await button.has({ className: including("MuiButton-text") }); |
| 203 | + await button.find(HTML({ className: including("MuiButton-endIcon") })).exists(); |
| 204 | + await button.find(HTML({ className: not(including("MuiButton-startIcon")) })).exists(); |
| 205 | + }, |
| 206 | +}; |
| 207 | + |
| 208 | +export const Ripple: ComponentStoryObj<typeof Component> = { |
| 209 | + args: { TouchRippleProps: { className: "touch-ripple" } }, |
| 210 | + async play() { |
| 211 | + await button.find(HTML({ className: including("touch-ripple") })).exists(); |
| 212 | + }, |
| 213 | +}; |
| 214 | + |
| 215 | +export const DisableRipple: ComponentStoryObj<typeof Component> = { |
| 216 | + args: { disableRipple: true, TouchRippleProps: { className: "touch-ripple" } }, |
| 217 | + async play() { |
| 218 | + await button.find(HTML({ className: including("touch-ripple") })).absent(); |
| 219 | + }, |
| 220 | +}; |
| 221 | + |
| 222 | +export const DisableElevation: ComponentStoryObj<typeof Component> = { |
| 223 | + args: { disableElevation: true }, |
| 224 | + async play() { |
| 225 | + await button.has({ className: including("MuiButton-disableElevation") }); |
| 226 | + }, |
| 227 | +}; |
| 228 | + |
| 229 | +export const FocusRipple: ComponentStoryObj<typeof Component> = { |
| 230 | + args: { TouchRippleProps: { classes: { ripplePulsate: "pulstat-focus-visible" } } }, |
| 231 | + async play() { |
| 232 | + await button.focus(); |
| 233 | + await button.find(HTML({ className: including("pulstat-focus-visible") })).exists(); |
| 234 | + }, |
| 235 | +}; |
| 236 | + |
| 237 | +export const DisableFocusRipple: ComponentStoryObj<typeof Component> = { |
| 238 | + args: { |
| 239 | + disableFocusRipple: true, |
| 240 | + TouchRippleProps: { classes: { ripplePulsate: "pulstat-focus-visible" } }, |
| 241 | + }, |
| 242 | + async play() { |
| 243 | + await button.focus(); |
| 244 | + await button.find(HTML({ className: including("MuiTouchRipple-rippleVisible") })).absent(); |
| 245 | + }, |
| 246 | +}; |
| 247 | + |
| 248 | +export const Anchor: ComponentStoryObj<typeof Component> = { |
| 249 | + args: { href: "https://google.com" }, |
| 250 | + async play() { |
| 251 | + await button.has({ |
| 252 | + className: including("MuiButton-root"), |
| 253 | + href: including("https://google.com"), |
| 254 | + }); |
| 255 | + }, |
| 256 | +}; |
| 257 | + |
| 258 | +export const ForwardClasses: ComponentStoryObj<typeof Component> = { |
| 259 | + args: { disabled: true, classes: { disabled: "disabledClassName" } }, |
| 260 | + async play() { |
| 261 | + await Button({ disabled: true }).has({ className: including("disabledClassName"), disabled: true }); |
| 262 | + }, |
| 263 | +}; |
| 264 | + |
| 265 | +export const Span: ComponentStoryObj<typeof Component> = { |
| 266 | + args: { component: "span" } as ComponentProps<typeof Component>, |
| 267 | + async play() { |
| 268 | + await button.exists(); |
| 269 | + await HTML.selector("span")({ className: including("MuiButton-root") }).exists(); |
| 270 | + }, |
| 271 | +}; |
0 commit comments