|
| 1 | +import React from "react"; |
| 2 | +import * as stylex from "@stylexjs/stylex"; |
| 3 | + |
| 4 | +function MenuDiv( |
| 5 | + props: { "data-highlighted"?: boolean | string } & Pick< |
| 6 | + React.ComponentProps<"div">, |
| 7 | + "children" | "tabIndex" |
| 8 | + >, |
| 9 | +) { |
| 10 | + const { children, ...rest } = props; |
| 11 | + return ( |
| 12 | + <div {...rest} sx={styles.menuDiv}> |
| 13 | + {children} |
| 14 | + </div> |
| 15 | + ); |
| 16 | +} |
| 17 | + |
| 18 | +function InteractiveBox( |
| 19 | + props: { |
| 20 | + "data-muted"?: boolean | string; |
| 21 | + "data-no-outline"?: boolean | string; |
| 22 | + } & Pick<React.ComponentProps<"div">, "children" | "tabIndex">, |
| 23 | +) { |
| 24 | + const { children, ...rest } = props; |
| 25 | + return ( |
| 26 | + <div {...rest} sx={styles.interactiveBox}> |
| 27 | + {children} |
| 28 | + </div> |
| 29 | + ); |
| 30 | +} |
| 31 | + |
| 32 | +export function App() { |
| 33 | + return ( |
| 34 | + <div style={{ display: "flex", flexDirection: "column", gap: 16, padding: 16 }}> |
| 35 | + <MenuDiv tabIndex={0}>Menu (focus me)</MenuDiv> |
| 36 | + <MenuDiv tabIndex={0} data-highlighted="true"> |
| 37 | + Menu (highlighted on focus) |
| 38 | + </MenuDiv> |
| 39 | + <InteractiveBox tabIndex={0}>Interactive Box</InteractiveBox> |
| 40 | + <InteractiveBox tabIndex={0} data-muted="true"> |
| 41 | + Interactive Box (muted) |
| 42 | + </InteractiveBox> |
| 43 | + <InteractiveBox tabIndex={0} data-no-outline="true"> |
| 44 | + Interactive Box (no outline) |
| 45 | + </InteractiveBox> |
| 46 | + </div> |
| 47 | + ); |
| 48 | +} |
| 49 | + |
| 50 | +const styles = stylex.create({ |
| 51 | + menuDiv: { |
| 52 | + backgroundColor: { |
| 53 | + default: "#f0f0f0", |
| 54 | + ":focus": "#bf4f74", |
| 55 | + ":focus-visible": "#bf4f74", |
| 56 | + ':focus:is([data-highlighted="true"])': "#2e86c1", |
| 57 | + ':focus-visible:is([data-highlighted="true"])': "#2e86c1", |
| 58 | + }, |
| 59 | + padding: 16, |
| 60 | + overscrollBehavior: "none", |
| 61 | + color: { |
| 62 | + default: null, |
| 63 | + ":focus": "white", |
| 64 | + ":focus-visible": "white", |
| 65 | + }, |
| 66 | + }, |
| 67 | + interactiveBox: { |
| 68 | + backgroundColor: "white", |
| 69 | + padding: 12, |
| 70 | + borderWidth: 2, |
| 71 | + borderStyle: "solid", |
| 72 | + borderColor: { |
| 73 | + default: "#ccc", |
| 74 | + ":hover": "#bf4f74", |
| 75 | + ':hover:is([data-muted="true"])': "#ddd", |
| 76 | + }, |
| 77 | + opacity: { |
| 78 | + default: null, |
| 79 | + ':hover:is([data-muted="true"])': 0.5, |
| 80 | + }, |
| 81 | + outline: { |
| 82 | + default: null, |
| 83 | + ":focus": "2px solid blue", |
| 84 | + ':focus:is([data-no-outline="true"])': "none", |
| 85 | + }, |
| 86 | + }, |
| 87 | +}); |
0 commit comments