@ostrich_development/ostrich-components
v1.1.15
Published
React components that look good out of the box and are **fully customizable through plain props**. Every component starts from a default style, and any style prop you pass is merged over it, so you only override what you need.
Readme
Ostrich Component Library for React
React components that look good out of the box and are fully customizable through plain props. Every component starts from a default style, and any style prop you pass is merged over it, so you only override what you need.
npm install @ostrich_development/ostrich-componentsimport { OstrichTabBar, OstrichForm } from "@ostrich_development/ostrich-components";
<OstrichTabBar tabs={["Home", "About", "Contact"]} onTabClick={(tab) => console.log(tab)} />Works with React 18 and 19. Built with tsup.
Customizing
Every component has a default look. Anything you pass is layered on top, so you only write what you want to change.
Prop naming (same pattern everywhere)
| Pattern | Meaning | Examples |
|---|---|---|
| style | The component's outermost element | <OstrichButton style={{ backgroundColor: "teal" }} /> |
| <part>Style | One part of the component | labelStyle, drawerStyle, menuStyle, fieldStyle, inputStyle, markerStyle |
| hover<Part>Style / active<Part>Style / disabled<Part>Style | That part in a state. Active means selected / open | hoverStyle, activeLabelStyle, hoverDrawerStyle, disabledSubmitStyle |
| titleStyle | Only real headings | form title, field titles, definition list title |
| labelStyle | Text on a control | tab text, dropdown text, button text, option text |
| captionStyle, moreTextStyle | Supporting text under a title | form fields |
| onClick | Clicking the component | OstrichButton, OstCard, TabItem |
| on<Thing>Click | Clicking one item inside it | onTabClick, onDrawerClick |
Data objects (tabs, drawers, dropdowns, form fields) accept the same style names for that one item: { title: "Home", labelStyle: {...}, activeStyle: {...} }. An item's own style wins over the component-wide one.
Old prop names still work (boxStyle, titleTextStyle, isActive, onSubmit...). Your editor shows them crossed out with the new name to use.
HTML attributes, classes and refs
Every component passes className, id, data-*, aria-*, extra event handlers (onKeyDown, onMouseEnter...) and ref to its outer element:
const formRef = useRef<HTMLDivElement>(null);
<OstrichForm ref={formRef} className="signup" data-testid="signup" fields={fields} />Text inputs also take inputProps (or inputProps on a field object) for attributes on the <input> itself:
fields={[{ id: "email", type: "email", inputProps: { name: "email", autoComplete: "email" } }]}Default styles are inline, so a
classNamecan't override a specific default property directly (inline styles beat classes). Change colors, fonts, corners and shadows with the theme (below), and anything else with the matching...Styleprop.
Theming
Every default color, the font, the corner radii and the shadows are CSS variables (--ost-*). Their fallbacks are the original look, so nothing changes until you set one. There are three ways to set them:
1. <OstrichTheme> around your app, or around one section. Set only what you want to change:
import { OstrichTheme } from "@ostrich_development/ostrich-components";
<OstrichTheme theme={{
colors: { accent: "#2bb3a3", active: "#d6f5f1", surface: "#fafafa" },
font: "Inter, sans-serif",
radius: 8, // or { sm: 6, md: 8, lg: 12 }
}}>
<App />
</OstrichTheme>Themes can be nested; the inner one wins. The wrapper uses display: contents, so it doesn't change your layout.
2. Plain CSS, which also works with dark mode, Tailwind arbitrary properties and CSS modules:
:root { --ost-accent: #2bb3a3; --ost-font: Inter, sans-serif; }
@media (prefers-color-scheme: dark) {
:root { --ost-text: #eee; --ost-surface: #2a2a2a; --ost-border: #555; --ost-card: #1e1e1e; }
}You can also scope it with className: .sidebar { --ost-surface: #222; } → <OstrichTabBar className="sidebar" ... />.
3. Generate the CSS from a theme object, e.g. for a global stylesheet or a Next.js layout:
import { ostrichThemeCSS } from "@ostrich_development/ostrich-components";
<style>{ostrichThemeCSS(myTheme)}</style> // :root { --ost-accent: ...; }
<style>{ostrichThemeCSS(myDarkTheme, ".dark")}</style> // .dark { ... }Explicit ...Style props always beat the theme.
Theme tokens
| Theme key | CSS variable | Default | Used for |
|---|---|---|---|
| colors.text | --ost-text | black | Text |
| colors.mutedText | --ost-muted-text | grey | Field captions |
| colors.softText | --ost-soft-text | #3d3d3d | Field extra text |
| colors.border | --ost-border | black | Lines around tabs, dropdowns, forms |
| colors.surface | --ost-surface | #efefef | Tabs, dropdowns, drawers, entries |
| colors.card | --ost-card | white | Clickable cards |
| colors.hover | --ost-hover | #a5a8a8 | Hovered tabs / dropdowns / drawers |
| colors.active | --ost-active | #c3e2fa | Selected tab, open dropdown, picked drawer |
| colors.accent | --ost-accent | #9cc6f0 | Buttons, selected options, valid status |
| colors.accentBorder | --ost-accent-border | #57a5f2 | Edge of selected options / valid status |
| colors.submit | --ost-submit | #8ebbfa | Form submit button |
| colors.disabled | --ost-disabled | #9d9e9e | Disabled buttons |
| colors.marker | --ost-marker | #bdbdbd | Unselected option bubbles, neutral status |
| colors.correct / correctBorder | --ost-correct / --ost-correct-border | #a8ffad / #57f25f | Correct answers |
| colors.wrong / wrongBorder | --ost-wrong / --ost-wrong-border | red / red | Wrong answers |
| colors.error | --ost-error | #d32f2f | "Why is this invalid?" messages |
| colors.correctText | --ost-correct-text | #2e7d32 | "Correct answer: ..." text |
| colors.link | --ost-link | blue | ODef word |
| colors.popup | --ost-popup | lightgrey | ODef popup |
| colors.focusRing | --ost-focus-ring | rgba(0,0,255,0.3) | Focused inputs |
| font | --ost-font | Gilroy, system-ui, sans-serif | All text |
| radius.sm / md / lg | --ost-radius-sm / -md / -lg | 10px / 15px / 20px | Dropdowns & entries / cards & buttons / forms |
| shadows.normal / soft / subtle / popup | --ost-shadow-normal / -soft / -subtle / -popup | | Cards & buttons / dropdowns / form fields / ODef popup |
Hover colors are computed from the current color, so a themed accent still darkens on hover.
Styling every part
Nothing is locked. Every piece a component draws has a default and a ...Style prop layered on top of it, and your styles are applied after the defaults (state styles like hover or pressed come last, and have their own props too).
| Component | Style props |
|---|---|
| OstCard | style, hoverStyle, pressedStyle; templates: contentStyle, imageAreaStyle, imageStyle, textStyle, titleStyle, captionStyle, bodyStyle, columnStyle |
| OstrichButton | style, hoverStyle, pressedStyle, disabledStyle, labelStyle, captionStyle, contentStyle, imageStyle |
| OstrichDropDown | style, hoverStyle, activeStyle, labelAreaStyle, labelStyle (+ hover/active), inputStyle, menuAreaStyle, menuContainerStyle, menuStyle, drawerStyle (+ hover/active), drawerLabelStyle |
| OstrichTabBar | style, tabAreaStyle, tabListStyle, tabStyle (+ hover/active), labelStyle (+ hover/active), drawer styles for dropdown tabs |
| OstrichForm | style, headerStyle, titleStyle, bodyStyle, fieldStyle, fieldContentStyle, titleRowStyle, fieldTitleStyle, bubbleStyle, captionStyle, moreTextStyle, detailsStyle, inputStyle, focusedInputStyle, optionStyle, markerStyle, selectedMarkerStyle, optionLabelStyle, fieldButtonStyle, messagesStyle, errorStyle, answerStyle, submitStyle, disabledSubmitStyle, submitLabelStyle, reviewStyle |
| Every field (FormText, FormMultipleChoice, ...) | style, contentStyle, titleRowStyle, titleStyle, bubbleStyle, bubbleAreaStyle, captionStyle, moreTextStyle, detailsStyle, imageStyle, imageCardStyle, messagesStyle, errorStyle, answerStyle |
| FormText | + inputStyle, focusedInputStyle |
| FormMultipleText | + inputRowStyle, inputAreaStyle, inputStyle, buttonAreaStyle, buttonStyle, buttonHoverStyle, entryRowStyle, entryStyle, entryHoverStyle |
| FormMultipleChoice | + optionsStyle, optionGroupStyle, optionRowStyle, optionStyle, markerAreaStyle, markerStyle, selectedMarkerStyle, optionLabelAreaStyle, optionLabelStyle, tabStyle (+ hover/active), tabLabelStyle (+ hover/active) |
| FormDropDownText | + inputStyle, drawerStyle, hoverDrawerStyle, menuStyle, and dropdownProps for anything else on the inner dropdown |
| OstrichSelectionBox | style, markerAreaStyle, markerStyle (+ selected / correct / wrong), labelAreaStyle, labelStyle |
| ODef | style (the word), popupStyle, contentStyle, rowStyle, termStyle, definitionStyle |
| DefinitionList / DefinitionRow | style, titleStyle, rowStyle, termStyle, definitionStyle, termTextStyle, definitionTextStyle |
In forms, any of a field component's props can be passed to every field with fieldProps={{ optionRowStyle: {...}, entryStyle: {...} }}, or to one field with fieldProps on its field object. Field objects also accept the inner-piece styles directly ({ id: "q1", type: "MC", bubbleStyle: {...} }). A field's own setting beats the form-wide one.
Props meant for a different component (e.g. a form-wide optionRowStyle reaching a text field) are ignored instead of leaking into the HTML.
Accessibility
Everything is usable with a keyboard and announced properly by screen readers, with no setup:
| Component | Keyboard | Screen readers hear |
|---|---|---|
| OstrichButton, clickable OstCard | Tab to it, Enter / Space to press | A button (disabled buttons are skipped by Tab) |
| OstrichTabBar | Tab into the bar, ← → / Home / End to move, Enter / Space to pick | A tab list, which tab is selected |
| OstrichDropDown | Enter / Space / ↓ to open, ↑ ↓ to move, Enter to pick, Esc to close | A button that opens a list, the highlighted option |
| Type-ahead fields (isInput, FormDropDownText) | Type to filter, ↑ ↓ to move, Enter to pick, Esc to close | A combo box with suggestions |
| Form fields | Normal typing / Tab | Each input is named by its field title and described by its caption; wrong answers are flagged |
| Multiple choice | Tab between options, Space to pick (clicking the option text works too) | Radio buttons (single choice) or checkboxes (multiple) |
| Status bubble | — | "Complete", "Not complete", "Correct" or "Incorrect" |
| reviewOnSubmit score | — | Read out when it appears |
| ODef | Tab to the word, Enter to open, Esc to close | A button that opens a dialog |
What you should still provide:
- A name for things without visible text:
aria-labelon a tab bar (<OstrichTabBar aria-label="Main" />) and on image-only buttons (or setlabel, which is used for the image's alt text). - Image descriptions:
imageAltonOstCard,imgAltonOstrichButton, andimgAlton form field objects that useimg. Leave them out for purely decorative images.
Form validation & answers
Why is this invalid? Every field explains itself under the input once the person leaves it (not while they're still typing). Clicking a greyed-out Submit shows every field's message at once, so people can see what's missing.
Where the explanation comes from, first match wins:
| Situation | Message |
|---|---|
| The browser rejects it (type: "email", "number", "url", or inputProps like pattern, minLength) | The browser's own message, e.g. Please include an '@' in the email address. |
| validResponse is a function that returns a string | That string |
| The field has invalidMessage | That text |
| A required field is empty | This field is required. (or the field's requiredMessage) |
| Anything else that fails | This answer isn't valid. |
| Multiple choice / multi-text below min | Pick at least 2. / Add at least 2 entries. |
| Trying to go past limit | You can pick up to 3. / You can add up to 3 entries. |
| Type-ahead value that isn't one of the options | Pick one of the suggestions. |
{ id: "age", type: "text", title: "Age",
validResponse: (v) => /^[0-9]+$/.test(v) || "Age must be a number" } // true = valid, string = why notOptional fields (required: false) never complain about being empty. Turn messages off with showErrors={false} on the form, and style them with errorStyle (form-wide or per field).
Showing the right answer. Add showsAnswer to the form. After a submission, any field with a correctResponse that was answered wrong reveals it:
- Text, multi-text and type-ahead fields show Correct answer: Paris under the input.
- Multiple choice turns the right option(s) green and a wrong pick red, and screen readers hear "(correct answer)" / "(wrong answer)".
It updates live: when the person fixes the answer, the reveal disappears. Turn it off for one field with showsAnswer: false on that field. Style it with answerStyle, and change the wording with answerLabel (default "Correct answer:"). It pairs well with allowResubmission.
Status bubbles after submitting. Before a submission the bubble is blue once a field is valid. After a submission, any field with a correctResponse turns green if it's right and red if it's wrong, and updates live if the person edits it. Fields without a correctResponse stay blue.
Code examples and workspaces
CodeExample shows read-only code with syntax colors, a Copy button, optional line numbers, highlighted lines, language tabs and a live preview. CodeWorkSpace is the editable version: Tab indents, Enter keeps the indentation, Reset goes back to the starting code, and Run executes it.
import { CodeExample, CodeWorkSpace } from "@ostrich_development/ostrich-components";
// One language
<CodeExample language="javascript" code={`console.log("Hello!")`} />
// Several, with tabs
<CodeExample lineNumbers highlightLines={[2]} languages={{ JavaScript: jsCode, Python: pyCode, Java: javaCode, "C#": csCode }} />
// With a live preview above the code
<CodeExample code={`<OstCard>Hi</OstCard>`}>
<OstCard>Hi</OstCard>
</CodeExample>
// An exercise: JavaScript runs in the browser, and the output is checked
<CodeWorkSpace
defaultValue={`const total = 2 + 2\nconsole.log(total)`}
expectedOutput="4"
onResult={(result) => console.log(result.isCorrect, result.output)}
/>- Languages colored: JavaScript, JSX, TypeScript, Python, Java, C#, HTML, CSS, JSON (and
"text"for none). Names like"js","py"or"C#"work too. - Running code: JavaScript runs in a Web Worker, so it can't touch your page, and a run longer than
timeout(3 s) is stopped, so an endless loop can't freeze anything. Other languages need your ownonRun(code, language), which can send the code to a server and return the text to show. - Grading:
expectedOutputcompares what was printed;check(result)returnstrue,falseor a sentence saying what's wrong. Ctrl/Cmd + Enter runs. - Styling: every part has a style prop (
headerStyle,codeStyle,inputStyle,outputStyle,lineNumberStyle,highlightLineStyle,runButtonStyle...),tokenStylesrestyles each kind of code ({ keyword: { color: "orange" } }), and the theme has code colors (codeBackground,codeText,codeKeyword,codeString,codeComment...) pluscodeFont.
Development
| Command | What it does |
|---|---|
| npm install | Install dependencies (run after pulling or after package.json changes) |
| npm run dev | Rebuild dist/ on every save |
| npm run build | Build dist/ once (ESM, CommonJS and type declarations) |
| npm run typecheck | Check types without building |
Try changes in a real app before publishing
From this folder:
npm run build
npm pack # creates ostrich_development-ostrich-components-X.Y.Z.tgzThen in your app:
npm install /path/to/OstrichComponentsReact/ostrich_development-ostrich-components-X.Y.Z.tgzThis installs exactly what npm would publish. Delete the .tgz afterwards (don't commit it). To go back to the published version, run npm install @ostrich_development/ostrich-components@latest in the app.
🚀 Publishing a new version (checklist)
Short version: commit everything →
npm version patch→npm publish→git push --follow-tags
One-time setup (new computer)
npm login # opens the browser to sign in to npmjs.com
npm whoami # should print your npm usernameYour npm account must be a member of the ostrich_development organization on npmjs.com.
Every release
1. Start clean and up to date
git pull
npm install
git status # must show "nothing to commit"; commit or stash firstnpm version (step 3) refuses to run if there are uncommitted changes.
2. Make sure it builds
npm run typecheck
npm run buildnpm publish runs both of these automatically too (the prepublishOnly script), so a broken build can't be published by accident. Running them now just catches problems before you bump the version.
3. Bump the version. Pick one:
npm version patch # 1.1.11 → 1.1.12 bug fixes only
npm version minor # 1.1.11 → 1.2.0 new features / new props, nothing breaks
npm version major # 1.1.11 → 2.0.0 anything that could break an existing appThis updates package.json, makes a git commit, and creates a tag like v1.1.12.
4. Preview what will be uploaded (optional but recommended)
npm run release:dryYou should see only dist/, package.json, readme.md and LICENSE. Nothing is uploaded.
5. Publish
npm publishIf your account has two-factor auth, npm will ask for a code (or add --otp=123456).
6. Push the version commit and tag to GitHub
git push --follow-tags7. Check it worked
npm view @ostrich_development/ostrich-components versionIt should print the new version. In your apps, run npm install @ostrich_development/ostrich-components@latest.
When something goes wrong
| Error | Fix |
|---|---|
| ENEEDAUTH / need auth | Run npm login |
| 403 ... cannot publish over the previously published versions | That version number is taken. Run npm version patch again and publish |
| 402 Payment Required / must be public | First publish of a scoped package: npm publish --access public (only needed once) |
| 403 Forbidden (not a version issue) | Your npm user isn't in the ostrich_development org, or you're logged into the wrong account (npm whoami) |
| Git working directory not clean | Commit or stash your changes, then rerun npm version |
| EOTP / one-time password required | npm publish --otp=<code from your authenticator> |
| Published, but the app doesn't see the change | In the app: npm install @ostrich_development/ostrich-components@latest, then restart the dev server |
| Published something broken | Publish a fixed patch right away. You can also run npm deprecate @ostrich_development/[email protected] "broken, use X.Y.Z+1". Avoid npm unpublish: it only works within 72 hours and that version number can never be reused |
Changelog
Unreleased (suggest publishing as 2.0.0, since some defaults changed)
Changed: multiple choice allows one answer by default, in forms too (forms used to allow many). Set
singleOption: false, or alimitabove 1, to allow several.Changed: answers are checked against both the form's
correctResponseanswer key (first) and the field's owncorrectResponse/correctValue; matching either counts as correct, and revealed answers highlight both. Numbers and text match, so175and"175"are the same answer.Large cleanup: styles are computed during render, shared helpers replace duplicated code, and strict TypeScript passes.
Type declarations (
index.d.ts) now ship with the package.Fixed: form
onSubmitnow receives(values, fields, previousValues), the submit button enables when the form is valid,reviewOnSubmitgrades correctly, string and number tabs work, the dropdowndrawerStyleapplies, multiple-choicelimitworks, and more.New:
pastAnswerData,showWrongAnswersandallowResubmissiononOstrichForm.OstrichButtonand the types are exported.Consistent prop names across all components (see Customizing). Old names still work but are deprecated.
Every component accepts
className,id,data-*,aria-*, extra event handlers andref. Text inputs acceptinputProps.New:
OstrichButtondisabled,hoverStyle,onClick; dropdownmenuStyle,drawerLabelStyle,onInputChange; per-fieldfieldStyle,titleStyle,inputStyleon form field objects.Theming: every default color, font, radius and shadow is a CSS variable. New
<OstrichTheme>,ostrichThemeCSS(),themeToCSSVars()andDEFAULT_THEME.The font now falls back to the system font (instead of the browser's serif default) when Gilroy isn't installed.
Accessibility: keyboard support and screen-reader roles/labels for every component (see Accessibility).
Fixed: a form field's
imgnever actually showed up; it now renders (withimgAlt).Fields explain why they're invalid (browser messages, validator strings,
invalidMessage,requiredMessage, min/limit messages). Clicking a disabled Submit reveals all of them.After a submission, status bubbles turn green (right) / red (wrong) for fields with a
correctResponse(showWrongAnswersis no longer needed for this).New
showsAnsweron forms: reveals thecorrectResponseafter a wrong submission (green/red options, "Correct answer:" line).OstrichFormtakes a whole-form answer key:correctResponse={{ 1: ["String"], 2: ["Integer"] }}(a field's owncorrectResponsewins).Multiple choice takes a controlled
value, andallowDeselect(tab-style options stay picked when clicked again, so they work as menus).OstrichTabBartakesopenOnHoverfor its dropdown tabs. Field objects acceptminLengthas another name formin.Fixed: a
validResponsethat expects a string no longer crashes the form on first render; a validator that throws counts as invalid.Every inner piece of every component has a
...Styleprop (see Styling every part); press effects arepressedStyle; forms takefieldProps.Fixed: a form opened from
pastAnswerDatawithreviewOnSubmitnow shows its "x / total correct" score right away.Fixed:
markerType="box"now draws a square-cornered box (it was a 50px circle), the same size as the bubble.Fixed: multiple-choice labels no longer overlap in narrow spaces; options move down a line instead.
Fixed: a standalone
FormMultipleChoicenow readssingleOptionanditemsPerRowfromfieldObjwhen the props aren't given.New:
CodeExample(read-only code with colors, tabs, copy and preview) andCodeWorkSpace(editable code that can run JavaScript and check the output). The theme gains code colors andcodeFont.Fixed: dropdown labels (and the search box placeholder) are now vertically centered. Override with
style={{ justifyContent: "flex-start" }}.Fixed: multiple-choice tabs (
template: "tabs") are all the same height; when one tab's text wraps, every tab grows to match.Breaking:
- Forms lock after one submission unless
allowResubmissionis set. - Inactive buttons ignore clicks.
{ tag, value }multiple-choice options storevalue.FormMultipleChoicenow applies itsstyleprop (1.x ignored it).- The form Submit button is 25% wide as its defaults always intended (1.x accidentally rendered it full width; pass
submitStyle={{ width: '100%' }}to keep that look). - A
validResponsefunction that returns a string now means invalid, because … (it used to count as valid). OstrichButton'sinactiveStyle/disabledStyleis now layered overstyleinstead of replacing it.
- Forms lock after one submission unless
1.0.0
- First release (React 18).
