Skip to content
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

Experimental WIP: strict-ui #719

Closed
wants to merge 50 commits into from
Closed

Experimental WIP: strict-ui #719

wants to merge 50 commits into from

Conversation

mxstbr
Copy link
Member

@mxstbr mxstbr commented Feb 24, 2020

Click here for background info. This is just an experimental prototype for me to test these ideas in practice.

This is what the entire API currently looks like (essentially it's theme-ui with the restrictions outlined in the doc above and way less API surface area):

/* @jsx jsx */
import { Grid, Flex, jsx, useStrictUI, ThemeProvider } from 'strict-ui';

<ThemeProvider theme={myTheme}>
  <Grid gap={2} columns={1}>
    <div sx={{ padding: 1 }} />
    <div sx={{ color: 'primary' }} />
  </Grid>
  <Flex flexDirection="column" gap={2}>
    <div sx={{ background: 'secondary' }} />
  </Flex>
</ThemeProvider>

Known issues

  • Responsive values don't work
  • red: 'red' in the theme breaks the "only theme values" detection
  • Doesn't block shorthands (mx, ml) or x-y properties (marginX)
  • Need to set * { margin: 0; } in reset
  • There is no way to float images
  • There is no way to specify display: none or display: inline-block?
  • What to do about margin: auto? Can't center anything
  • Fix undefined/null values
  • display: list-item and padding-inline-start accepts non-theme values

@@ -4,7 +4,7 @@ import { Global } from '@emotion/core'
import { scales, aliases, transforms } from './css'
import sanitize from './sanitize.css'

export { Grid, ThemeProvider, useThemeUI as useStrictUI } from 'theme-ui'
export { Grid, Flex, ThemeProvider, useThemeUI as useStrictUI } from 'theme-ui'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

* Licensed under the MIT License.
*/
// Copied from https://cdnjs.cloudflare.com/ajax/libs/sanitize.css/2.0.0/sanitize.min.css
injectGlobal`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there's a way to approach this reset more dynamically, rather than a blanket global style? This way you'll be able to use strict-ui components alongside others.

So for instance in my Stack and Inline component, when it's rendered as an ol or ul I make use of a shared reset:

export const Stack: React.FC<StackProps> = ({ gap = 3, ...props }) => (
  <div
    {...props}
    sx={{
      /* …stack styles */
      /* …reset returns the following: */
      /* Reset: ensure direct child list-items render without bullets */
      "& > li": {
        listStyleType: "none",
        "&:before": {
          position: "absolute",
          content:
            '"\\200B"' /* Add zero-width space to prevent VoiceOver disable */,
        },
      },
    }}
  />
);

Might be worth at taking a look at how @markdalgleish tackled this in Braid!
https://twitter.com/markdalgleish/status/1223161650246602752

@joe-bell
Copy link
Contributor

joe-bell commented Mar 20, 2020

Just a variant idea for if flexWrap: wrap is defined:

const inline = (gap: number) => ({
  /* styles to add to the parent */
  overflow: 'hidden',
  alignItems: 'center',
  margin: (gap / 2) * -1,
  /* styles for the children */
  '& > *': {
    margin: gap / 2,
  },
});

ℹ️ The only caveat here is we're relying on negative outer margins which are counterracted by the child elements to appear as a "normal" gap. So although this won't affect the flow of adjacent components, it will require some transformation of the margin prop value on the parent.

Then we can render elements nicely inline like so:

Inline Component Demo

@joe-bell
Copy link
Contributor

joe-bell commented Apr 8, 2020

Just an update: I've actually added that Inline component above (and some other flex-based layout primitives) to a package called raam.

Please feel free to extend upon this with your stricter type strategy! I'd be happy to help out

@gatsby-cloud
Copy link

gatsby-cloud bot commented Jul 30, 2020

Gatsby Cloud Build Report

🚩 Your build failed. See the build logs here

@lachlanjc lachlanjc added the enhancement New feature or request label Dec 3, 2020
@lachlanjc
Copy link
Member

@mxstbr Hey! What are you thinking about this PR now?

@hasparus can follow up on what’s happening with our TypeScript support right now.

@mxstbr
Copy link
Member Author

mxstbr commented Dec 7, 2020

Going to close it for now as it was a nice experiment but would need a lot more work to be usable and I don't have the time to work on this!

@mxstbr mxstbr closed this Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants