MUI query builder

A query builder made of Material UI components: TextField, Select, Autocomplete, ToggleButtonGroup. MIT, no MUI X license, one command to install as source.

MIT · Material UI · Emotion · React 18+

licenseMIT
needs@mui/material + Emotion
MUI XNot required
installOne shadcn add

The MUI builder that shadcn add installs, live on this page. Edit a rule and watch the exports.

Install it

One command copies the MUI builder and the kit-agnostic core it shares with the other kits into components/qnot, and installs @qnot/core and @qnot/react. MIT licensed.

pnpm dlx shadcn@latest add https://coss.com/qnot/r/query-builder-mui.json

Installs @mui/material, @mui/icons-material and Emotion. The builder wraps itself in its own ThemeProvider (light or dark from the dark class on <html>), so it needs neither your theme nor CssBaseline; edit themeFor in the file to match your app.

Source

4 files, exactly what installs

Use it.

Describe your fields, create a store, render the builder. The store's onChange hands you the query.
fields.ts
Filters.tsx

Pickers are MUI Selects and Autocompletes, values are TextFields, AND / OR is a ToggleButtonGroup, and the add menu is a Menu. All of it sits on @qnot/react's hooks, which own the state.

Read the query with the store's onChange, useQuery() or store.getQuery(), and encode it with any format.

What you get.

The kit is only the controls. Everything else comes from the qnot store underneath.

Questions people ask

Is it free? Does it need MUI X?
Yes, and no. The builder is MIT licensed and uses only @mui/material and @mui/icons-material (both MIT) with Emotion. No MUI X package or license is involved.
Do I need to use shadcn to install it?
Only the CLI, once: shadcn add copies the file into your project and installs the npm packages. It needs a components.json, which shadcn init creates; you do not have to use any shadcn/ui components afterwards.Install with shadcn
Does it follow my MUI theme?
It wraps itself in its own ThemeProvider and picks light or dark from the dark class on <html>, so it works without your theme or CssBaseline. To match your app, edit themeFor in the installed file, or remove the wrapper and let it inherit your theme.
Which MUI version is it built for?
This site runs it on @mui/material 9.5. It imports components by path (@mui/material/Autocomplete and so on), which keeps the bundle to what it uses.
Does it work with the Next.js App Router?
Yes. The builder is a client component. If you use MUI elsewhere on the page, keep your usual AppRouterCacheProvider from @mui/material-nextjs so Emotion's styles are collected on the server.
How do I get SQL or a MongoDB filter out of it?
The store holds the query as plain JSON. Encode it with a codec from @qnot/core/formats: sqlFormat({ dialect: "postgres", params: "numbered" }) gives SQL with bound parameters; mongo and jsonlogic give filters.Formats