Skip to content

Commit

Permalink
more docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle committed Apr 25, 2024
1 parent e10a6fa commit 5b66f6a
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 26 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ repos:
types_or: [javascript, jsx, ts, tsx, css, json, markdown]
entry: npm run prettier
language: system
exclude: '^docs/.*'
- id: js-lint
name: js-lint
types_or: [ts, tsx]
Expand Down
45 changes: 41 additions & 4 deletions docs/components.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
::: fastui.components
options:
docstring_options:
ignore_init_summary: false
members: - Text - Paragraph - PageTitle - Div - Page - Heading - Markdown - Code - Json - Button - Link - LinkList - Navbar - Modal - ServerLoad - Image - Iframe - FireEvent - Error - Spinner - Toast - Custom - Table - Pagination - Display - Details - Form - FormField - ModelForm - Footer - AnyComponent - FormFieldBoolean - FormFieldFile - FormFieldInput - FormFieldSelect - FormFieldSelectSearch
options:
inherited_members: true
docstring_options:
ignore_init_summary: false
members:
- Text
- Paragraph
- PageTitle
- Div
- Page
- Heading
- Markdown
- Code
- Json
- Button
- Link
- LinkList
- Navbar
- Modal
- ServerLoad
- Image
- Iframe
- FireEvent
- Error
- Spinner
- Toast
- Custom
- Table
- Pagination
- Display
- Details
- Form
- FormField
- ModelForm
- Footer
- AnyComponent
- FormFieldBoolean
- FormFieldFile
- FormFieldInput
- FormFieldSelect
- FormFieldSelectSearch

<!-- TODO: don't render attributes in TOC -->
41 changes: 37 additions & 4 deletions src/npm-fastui/src/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export type JsonData =
}
export type AnyEvent = PageEvent | GoToEvent | BackEvent | AuthEvent
export type NamedStyle = 'primary' | 'secondary' | 'warning'
/**
* Display mode for a value.
*/
export type DisplayMode =
| 'auto'
| 'plain'
Expand All @@ -72,9 +75,6 @@ export type SelectOptions = SelectOption[] | SelectGroup[]

/**
* Text component that displays a string.
*
* !!! abstract "Component Demo"
* [Text](https://fastui-demo.onrender.com/components#text)
*/
export interface Text {
text: string
Expand Down Expand Up @@ -338,6 +338,9 @@ export interface Custom {
className?: ClassName
type: 'Custom'
}
/**
* Table component.
*/
export interface Table {
data: DataModel[]
columns: DisplayLookup[]
Expand All @@ -358,13 +361,16 @@ export interface DisplayLookup {
field: string
tableWidthPercent?: number
}
/**
* Pagination component to use with tables.
*/
export interface Pagination {
page: number
pageSize: number
total: number
pageQueryParam?: string
className?: ClassName
type: 'Pagination'
pageQueryParam?: string
pageCount: number
}
/**
Expand All @@ -377,12 +383,18 @@ export interface Display {
value: JsonData
type: 'Display'
}
/**
* Details associated with displaying a data model.
*/
export interface Details {
data: DataModel
fields: DisplayLookup[]
className?: ClassName
type: 'Details'
}
/**
* Form component.
*/
export interface Form {
submitUrl: string
initial?: {
Expand All @@ -405,6 +417,9 @@ export interface Form {
)[]
type: 'Form'
}
/**
* Form field for basic input.
*/
export interface FormFieldInput {
name: string
title: string[] | string
Expand All @@ -420,6 +435,9 @@ export interface FormFieldInput {
autocomplete?: string
type: 'FormFieldInput'
}
/**
* Form field for text area input.
*/
export interface FormFieldTextarea {
name: string
title: string[] | string
Expand All @@ -436,6 +454,9 @@ export interface FormFieldTextarea {
autocomplete?: string
type: 'FormFieldTextarea'
}
/**
* Form field for boolean input.
*/
export interface FormFieldBoolean {
name: string
title: string[] | string
Expand All @@ -449,6 +470,9 @@ export interface FormFieldBoolean {
mode?: 'checkbox' | 'switch'
type: 'FormFieldBoolean'
}
/**
* Form field for file input.
*/
export interface FormFieldFile {
name: string
title: string[] | string
Expand All @@ -462,6 +486,9 @@ export interface FormFieldFile {
accept?: string
type: 'FormFieldFile'
}
/**
* Form field for select input.
*/
export interface FormFieldSelect {
name: string
title: string[] | string
Expand All @@ -487,6 +514,9 @@ export interface SelectGroup {
label: string
options: SelectOption[]
}
/**
* Form field for searchable select input.
*/
export interface FormFieldSelectSearch {
name: string
title: string[] | string
Expand All @@ -503,6 +533,9 @@ export interface FormFieldSelectSearch {
placeholder?: string
type: 'FormFieldSelectSearch'
}
/**
* Form component generated from a Pydantic model.
*/
export interface ModelForm {
submitUrl: string
initial?: {
Expand Down
12 changes: 3 additions & 9 deletions src/python-fastui/fastui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@


class Text(_p.BaseModel, extra='forbid'):
"""Text component that displays a string.
!!! abstract "Component Demo"
[Text](https://fastui-demo.onrender.com/components#text)
"""
"""Text component that displays a string."""

text: str
"""The text to display."""
Expand Down Expand Up @@ -160,8 +156,6 @@ def __get_pydantic_json_schema__(
return json_schema


# see https://github.com/PrismJS/prism-themes
# and https://cdn.jsdelivr.net/npm/react-syntax-highlighter@15.5.0/dist/esm/styles/prism/index.js
CodeStyle = _te.Annotated[_t.Union[str, None], _p.Field(serialization_alias='codeStyle')]
"""
Code style to apply to a `Code` component.
Expand All @@ -170,8 +164,8 @@ def __get_pydantic_json_schema__(
codeStyle: The code style to apply. If None, no style is applied.
See Also:
- https://github.com/PrismJS/prism-themes
- https://cdn.jsdelivr.net/npm/react-syntax-highlighter@15.5.0/dist/esm/styles/prism/index.js
- [PrismJS Themes](https://github.com/PrismJS/prism-themes)
- [PrismJS Theme Index](https://cdn.jsdelivr.net/npm/react-syntax-highlighter@15.5.0/dist/esm/styles/prism/index.js)
"""


Expand Down
33 changes: 26 additions & 7 deletions src/python-fastui/fastui/components/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@


class DisplayMode(str, enum.Enum):
"""Display mode for a value."""

auto = 'auto' # default, same as None below
plain = 'plain'
datetime = 'datetime'
Expand All @@ -27,37 +29,54 @@ class DisplayMode(str, enum.Enum):


class DisplayBase(pydantic.BaseModel, ABC, defer_build=True):
"""Base class for display components."""

mode: _t.Union[DisplayMode, None] = None
"""Display mode for the value."""

title: _t.Union[str, None] = None
"""Title to display for the value."""

on_click: _t.Union[events.AnyEvent, None] = pydantic.Field(default=None, serialization_alias='onClick')
"""Event to trigger when the value is clicked."""


class DisplayLookup(DisplayBase, extra='forbid'):
"""
Description of how to display a value looked up from data, either in a table or detail view.
"""
"""Description of how to display a value looked up from data, either in a table or detail view."""

field: str
# percentage width - 0 to 100, specific to tables
"""Field to display."""

table_width_percent: _t.Union[_te.Annotated[int, _at.Interval(ge=0, le=100)], None] = pydantic.Field(
default=None, serialization_alias='tableWidthPercent'
)
"""Percentage width - 0 to 100, specific to tables."""


class Display(DisplayBase, extra='forbid'):
"""
Description of how to display a value, either in a table or detail view.
"""
"""Description of how to display a value, either in a table or detail view."""

value: _types.JsonData
"""Value to display."""

type: _t.Literal['Display'] = 'Display'
"""The type of the component. Always 'Display'."""


class Details(pydantic.BaseModel, extra='forbid'):
"""Details associated with displaying a data model."""

data: pydantic.SerializeAsAny[_types.DataModel]
"""Data model to display."""

fields: _t.Union[_t.List[DisplayLookup], None] = None
"""Fields to display."""

class_name: _class_name.ClassNameField = None
"""Optional class name to apply to the details component."""

type: _t.Literal['Details'] = 'Details'
"""The type of the component. Always 'Details'."""

@pydantic.model_validator(mode='after')
def _fill_fields(self) -> _te.Self:
Expand Down
Loading

0 comments on commit 5b66f6a

Please sign in to comment.