-
Notifications
You must be signed in to change notification settings - Fork 12
ZIndex: base implementation + story #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@cambly/syntax-core": minor | ||
"@syntax/storybook": minor | ||
--- | ||
|
||
ZIndex: basic implementation + story |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Meta } from "@storybook/addon-docs"; | ||
import ZIndex from "./ZIndex"; | ||
|
||
<Meta title="z-Index" /> | ||
|
||
# z-Index | ||
|
||
[getZIndex](https://cambly-syntax.vercel.app/?path=/docs/z-index--docs) is a utility function that returns a z-index value based on the layer and local layer. | ||
somethiiing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``` | ||
<Navbar zIndex={getZIndex("sticky")} /> | ||
<Modal zIndex={getZIndex("modal")} /> | ||
``` | ||
|
||
## Parameters | ||
|
||
- `layer`: The layer to get the z-index for. | ||
|
||
- Default: `base` | ||
- Options: | ||
- `base`: 0 | ||
- `menu`: 10 | ||
- `sticky`: 20 | ||
- `fixed`: 30 | ||
- `modal`: 40 | ||
- `popup`: 50 | ||
|
||
- `localLayer`: An optional parameter to manually tweak the z-index within each layer. | ||
- Usage: | ||
- getZIndex recognizes that there are occasional needs to have multiple things stacked in the same layer. | ||
- For example, two modals existing in the same layer. In these occasions, you can pass a localLayer to the function to manually tweak the z-index within each layer. | ||
- Default: `0` | ||
- Options: `-3` | `-2` | `-1` | `0` | `1` | `2` | `3` | ||
|
||
<ZIndex /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import React, { useState } from "react"; | ||
import Box from "../../../packages/syntax-core/src/Box/Box"; | ||
import Button from "../../../packages/syntax-core/src/Button/Button"; | ||
import Typography from "../../../packages/syntax-core/src/Typography/Typography"; | ||
import Modal from "../../../packages/syntax-core/src/Modal/Modal"; | ||
import getZIndex from "../../../packages/syntax-core/src/getZIndex"; | ||
|
||
import "@cambly/syntax-design-tokens/dist/css/variables.css"; | ||
|
||
export default function ZIndex() { | ||
const [currentZIndex, setCurrentZIndex] = useState(-10); | ||
const [openModal, setOpenModal] = useState(false); | ||
|
||
return ( | ||
<Box display="flex" direction="column" gap={4}> | ||
<Box> | ||
<Typography size={400} weight="medium"> | ||
Current Z-Index: {currentZIndex} | ||
</Typography> | ||
<Box display="flex" gap={4}> | ||
<Button | ||
text="Increase Z-Index Layer" | ||
onClick={() => setCurrentZIndex(currentZIndex + 10)} | ||
/> | ||
<Button | ||
text="Decrease Z-Index Layer" | ||
onClick={() => setCurrentZIndex(currentZIndex - 10)} | ||
/> | ||
<Button text="Open Modal" onClick={() => setOpenModal(true)} /> | ||
</Box> | ||
</Box> | ||
<Box | ||
height={1000} | ||
width="100%" | ||
backgroundColor="gray100" | ||
display="flex" | ||
direction="column" | ||
gap={4} | ||
border="primary" | ||
> | ||
<Box position="relative"> | ||
<Box | ||
position="absolute" | ||
width="100%" | ||
height={1000} | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
backgroundColor="gray900" | ||
dangerouslySetInlineStyle={{ | ||
__style: { | ||
zIndex: currentZIndex, | ||
}, | ||
}} | ||
> | ||
<Typography color="white" weight="medium"> | ||
demonstration layer of z-index: {currentZIndex} | ||
</Typography> | ||
</Box> | ||
</Box> | ||
<Box | ||
width="100%" | ||
height={64} | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
backgroundColor="sky" | ||
dangerouslySetInlineStyle={{ | ||
__style: { | ||
zIndex: getZIndex("sticky"), | ||
}, | ||
}} | ||
> | ||
Theoretical sticky navbar (sticky layer) | ||
</Box> | ||
|
||
<Box display="flex" direction="column"> | ||
<Box | ||
width="100%" | ||
height={200} | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
backgroundColor="slate" | ||
dangerouslySetInlineStyle={{ | ||
__style: { | ||
zIndex: getZIndex("base"), | ||
}, | ||
}} | ||
> | ||
Theoretical main content (base layer) | ||
</Box> | ||
|
||
<Box | ||
width="100%" | ||
height={200} | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
backgroundColor="teal" | ||
dangerouslySetInlineStyle={{ | ||
__style: { | ||
zIndex: getZIndex("menu"), | ||
}, | ||
}} | ||
> | ||
Theoretical menu content (menu layer) | ||
</Box> | ||
|
||
<Box | ||
width="100%" | ||
height={200} | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
backgroundColor="lilac" | ||
dangerouslySetInlineStyle={{ | ||
__style: { | ||
zIndex: getZIndex("fixed"), | ||
}, | ||
}} | ||
> | ||
Theoretical fixed content (fixed layer) | ||
</Box> | ||
</Box> | ||
</Box> | ||
|
||
{openModal && ( | ||
<Modal | ||
header="Theoretical Modal" | ||
onDismiss={() => setOpenModal(false)} | ||
zIndex={getZIndex("modal")} | ||
> | ||
<Box> | ||
<Typography>Theoretical modal content (modal layer)</Typography> | ||
<Typography> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do | ||
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut | ||
enim ad minim veniam, quis nostrud exercitation ullamco laboris | ||
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in | ||
reprehenderit in voluptate velit esse cillum dolore eu fugiat | ||
nulla pariatur. Excepteur sint occaecat cupidatat non proident, | ||
sunt in culpa qui officia deserunt mollit anim id est laborum. | ||
</Typography> | ||
</Box> | ||
</Modal> | ||
)} | ||
</Box> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* [getZIndex](?path=/docs/ZIndex--docs) is a utility function that returns a z-index value based on the layer and local layer. | ||
* | ||
* Usage: | ||
* ``` | ||
* <Navbar zIndex={getZIndex("sticky")} /> | ||
* <Modal zIndex={getZIndex("modal")} /> | ||
* ``` | ||
*/ | ||
export default function getZIndex( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How are you thinking the migration process would work, to move from our current z-indexes to these? Would we need to migrate all z-indexes at once? |
||
/** | ||
* The layer to get the z-index for. | ||
* | ||
* * `base`: 0 | ||
* * `menu`: 10 | ||
* * `sticky`: 20 | ||
* * `fixed`: 30 | ||
* * `modal`: 40 | ||
* * `popup`: 50 | ||
* | ||
* @defaultValue `base` | ||
*/ | ||
layer: "base" | "menu" | "sticky" | "fixed" | "modal" | "popup" = "base", | ||
/** | ||
* getZIndex recognizes that there are occasional needs to have multiple things stacked in the same layer. | ||
* For example, two modals existing in the same layer. In these occasions, you can pass a localLayer to the function to manually tweak the z-index within each layer. | ||
* | ||
* @defaultValue `0` | ||
*/ | ||
localLayer: -3 | -2 | -1 | 0 | 1 | 2 | 3 = 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How will folks know which localLayer to choose? |
||
): number { | ||
const layerIndex = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How well do these particular layers correspond to how we are using z-indexes in the app right now? I think it would be helpful to audit where we currently need z-indexes and for what types of components. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep in mind that some z-indexes might not even be explicitly set in our code. For example, it seems that the MUI Dialog component has a z-index of 1300 (see previous discussion), and it appears we are still using that in some places in our code. |
||
base: 0, | ||
menu: 10, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having comments/explanations for each of these layers will be really helpful, so people know which one is appropriate for their use case. Just from the names, I'm not sure when to use "base", "sticky", or "fixed", and when I should use "modal" vs "popup". |
||
sticky: 20, | ||
fixed: 30, | ||
modal: 40, | ||
popup: 50, | ||
} as const; | ||
|
||
return layerIndex[layer] + localLayer; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autodocs unfortunately dont work here because it's a function and not an actual component. so i manually created docs on how to use this function