Skip to content

Use of Theme-UI components for native html elements #1038

Answered by lachlanjc
dowi asked this question in General
Discussion options

You must be logged in to vote

This isn’t the easiest, but it’s totally doable. There are 3 parts:

  1. Make a Box/div/etc around the components where you’ll style the children
  2. Add a CSS selector for each tag you’re styling
  3. For each selector, use the theme variant plus the base styles the components internally use

So for example:

<Box
    as="form"
	sx={{
		'input[type=text],select,textarea': {
			variant: 'forms.input',
			display: 'block',
			width: '100%',
			p: 2,
			appearance: 'none',
			fontSize: 'inherit',
			lineHeight: 'inherit'
		},
		label: { variant: 'forms.label', mb: 3 }
	}}
>
	<label>
		Name:
		<input type="text" name="name" />
	</label>
	<label>
		Bio:
		<textarea />
	</label>
	<label>
		Pick your favorit…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by hasparus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants