Current section
Files
Jump to
Current section
Files
README.md
# Doggo[](https://hex.pm/packages/doggo)  [](https://coveralls.io/github/woylie/doggo)<img src="https://github.com/woylie/doggo/raw/main/assets/doggo.png" alt="Illustration of a happy Shiba Inu dog wearing a traditional Japanese kimono. The dog is centered within a circular frame, adorned with decorative patterns that include waves and stripes, indicative of a Japanese aesthetic. The Shiba Inu is smiling with its tongue out, suggesting a cheerful and playful demeanor. The kimono features bold red and white accents, complementing the dog's tan and white fur." width="200"/>Headless UI component collection for Phoenix, focused on semantics andaccessibility.For a full list of available components, please refer to the[documentation](https://hexdocs.pm/doggo/Doggo.html).## InstallationThe package can be installed by adding `doggo` to your list of dependencies in`mix.exs`:```elixirdef deps do [ {:doggo, "~> 0.9.1"} ]end```## UsageUse `Doggo.Components` in your core components module or in a separate module.`Doggo.Components` defines macros that generate Phoenix components.```elixirdefmodule MyAppWeb.CoreComponents do use Doggo.Components use Phoenix.Component build_alert() build_alert_dialog() build_button( modifiers: [ size: [values: ["normal", "small"], default: "normal"] ] )end```Each modifier results in an additional attribute that is translated into a CSSclass. You can use the button defined above like this:```html<.button size="small">Edit</.button>```Most of the components have a base class that matches the component name.By default, `Doggo.modifier_class_name/2` is used to build the CSS class namefor modifier attributes. The button above would be rendered with the class`"button is-small"`.You can override both the base class and the modifier class function:```elixirdefmodule MyAppWeb.CoreComponents do use Doggo.Components use Phoenix.Component build_button( base_class: "alt-button", modifiers: [small: [size: ["normal", "small"], default: "normal"]], class_name_fun: &MyAppWeb.CoreComponents.modifier_class/2 ) def modifier_class(name, value) do "#{name} #{value}" endend```With these changes, the class would now be `"alt-button size-small`. To removethe base class, just set it to `nil`.It is also possible to change the name of the generated component, which can beuseful if you want to compile multiple variants of the same component, or ifyour design system uses different names.```elixirbuild_button(name: :alt_button, base_class: "alt-button")```This button could be used with:```elixir<.alt_button>Edit</.alt_button>```Refer to the `Doggo.Components` module documentation for more information aboutthe options and the individual components.### StorybookDoggo can generate[Phoenix Storybook](https://hex.pm/packages/phoenix_storybook) stories for thegenerated components. After you followed the installation instructions ofPhoenix Storybook, you can run a mix task to generate the stories:```bashmix dog.gen.stories -m MyAppWeb.CoreComponents -o storybook --all```Here, `MyAppWeb.CoreComponents` is the module in which you added`use Doggo.Components`, and `storybook` is the path to the storybook folder.The task will only generate story modules for the components that youconfigured. The stories will include variations for all configured modifiers.You don't need to update the stories after changing the modifiers of acomponent. However, you'll need to run the task again after adding newcomponents to your module, or potentially after a new Doggo version wasreleased.The task will ask for confirmation to overwrite existing stories. To onlywrite the story for a single component, you can run:```bashmix dog.gen.stories -m MyAppWeb.CoreComponents -o storybook -c button```### PurgeCSSIf you use PurgeCSS, you can get a list of CSS class names of all configuredcomponents:```bashmix dog.classes -m MyAppWeb.CoreComponents -o assets/modifiers.txt```Add the generated file to your PurgeCSS configuration.## Design decisions- Favor semantic HTML elements over CSS classes for structure and clarity.- Adhere to accessibility guidelines with appropriate ARIA attributes and roles.- Utilize semantic HTML and ARIA attributes for style bindings to states, rather than relying on CSS classes.- Where state or variations can not be expressed semantically, use modifier classes named `.is-*` or `.has-*`.- The library is designed without default styles and does not prefer any particular CSS framework.## Demo appThe repository contains a demo application that renders a storybook with allcomponents using their default options. For some of the components, CSS wasadded, while others are still unstyled.The demo application is deployed at: https://woylie-doggo.fly.devTo run the application locally:```bashgit clone git@github.com:woylie/doggo.gitcd doggo/demomix setupmix phx.server```The storybook can be accessed at http://localhost:4000.## StatusThe library is actively developed. Being in its early stages, the library maystill undergo significant changes, including potential breaking changes.### Maturity LevelsEach component in the library is marked with one of four maturity levels.- **Experimental**: These components are in the early development phase. They are incomplete, have unstable APIs, and are subject to significant changes. Not recommended for production use.- **Developing**: Components at this stage have complete semantics, but interactivity features may still be missing. The API may still change based on feedback and testing. Suitable for internal testing and early feedback.- **Refining**: Feature-complete components with a stable API, full configurability, and all required keyboard interactivity for accessibility implemented. The focus is on identifying and fixing remaining issues. Suitable for broader testing and cautious production use.- **Stable**: Fully developed, tested, and ready for production use. These components have a stable API, are fully interactive, include a complete storybook module, and have exemplary CSS styles defined.## FeedbackIf you encounter any issues with a component, have suggestions for improvements,or need a component for a specific use case that isn't currently available,please don't hesitate to open a[Github issue](https://github.com/woylie/doggo/issues).