Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[62153] Update documentation for StatusButton component (#18449)

Henriette Dargef90a665e10aa
diff --git a/lookbook/docs/components/status_button.md.erb b/lookbook/docs/components/status_button.md.erb
index 08752975466..4bec5c29dd9 100644
--- a/lookbook/docs/components/status_button.md.erb
+++ b/lookbook/docs/components/status_button.md.erb
@@ -1,4 +1,6 @@
-This component defines a colored status button with an action menu to select other statuses. The component is optionally marked readonly, resulting in disabling the action menu.
+The Status button communicates the current status of something (like a meeting or a work package) using a label and a colour. Optionally, it allows the user to change the status to something else. The button triggers an action menu with alternate statuses. In read-only mode, the status button does not offer any interaction.
+
+The colours adapt automatically to the currently active mode (light/dark/light high contrast).
## Overview
@@ -6,43 +8,70 @@ This component defines a colored status button with an action menu to select oth
## Anatomy
-The component provides two use-cases:
+The component provides two variants:
-**1. Using colors only**
+**1. With colour markers**
-If you are providing `StatusOption` with only the `color` property set, it will use that to color the button of the component. For any selectable status items, the color will be shown as a small square using the `icon_for_color` helper used in various places of the administration.
+For any selectable status item, a small colour marker will be displayed. The colour of this marker is determined by our internal colour helpers.
-**2. Using icons and colors**
+<%= embed OpPrimer::StatusButtonComponentPreview, :playground %>
-If you provide `StatusOption` with `icon` and `color` properties set, the color will be used for the button only, and the icon will be used to provide a leading visual icon. In the action menu dropdown, the icons will also be used as a leading icon. Colors will not be shown in the dropdown.
+**2. With icons and colours**
+The button will be coloured, along with a leading icon in the foreground colour (the same as the text). The action dropdown menu will also show icons; the dropdown will not, however, show colours.
+<%= embed OpPrimer::StatusButtonComponentPreview, :with_icon %>
## Best practices
**Do**
-- Provide colors using the `Color` model.
+- Use the component when each status needs a colour. (Eg. meeting or work package status)
+- Specify the colour for each status; these colours are not automatically set via Primer and must be manually entered. However, using named Primer colour variables is encouraged (although a hex code will also work, thanks to the internal colour helpers who will translate it to other colour modes).
**Don't**
-- Don't use the component if the status is not colored. You can simply use an ActionMenu for this case.
+- Don't use the component if the status is not coloured. You can simply use an ActionMenu for this case.
## Used in
-The component is used in meetings to signal the status of the meeting, as well as providing options to change it. It will be used in the future for the work package status.
+The component is used in:
+
+* Meetings to signal the status of the meeting, as well as providing options to change it.
+* It will be used in the future for the work package status.
## Examples
For detailed examples have a look at the other [preview examples](/lookbook/inspect/OpenProject/Primer/status_button/playground) of the component.
-This is an exemplary playground of the `OpPrimer::StatusButtonComponent`.
+This is an example playground of the `OpPrimer::StatusButtonComponent`.
<%= embed OpPrimer::StatusButtonComponentPreview, :playground, panels: %i[params source] %>
## Technical notes
-The StatusButton component is a composition of a Primer Button and Primer ActionMenu. You provide options of statuses using the `OpPrimer::StatusButtonOption`. In there, you can pass a name, icon, color. All other options will be passed to the `ActionMenu` item.
+The StatusButton component is a composition of a Primer Button and Primer ActionMenu. You provide options of statuses using the `OpPrimer::StatusButtonOption`. In there, you can pass:
+
+* `name`: (required) the name of the option
+* `icon`: (optional) the leading icon
+* `color_ref`: (optional) The reference of the object to be coloured (for persisted items (like WorkPackage status or type), this is the ID, otherwise some other unique identifier)
+* `color_namespace`: (optional, although it is required when setting `color_ref`) The namespace is usually the name of the coloured objects (e.g "status", "type", "meeting_status".
+
+The `color_ref` and `color_namespace` are used together to build internally the highlighting classes for the options (e.g `__hl_inline_status_1`)
+
+**Note** For this to work, your `color_namespace` has to be registered so that the classes are created beforehand. Have a look [here](https://github.com/opf/openproject/blob/dev/app/views/highlighting/styles.css.erb) on how this is done for the already existing namespaces.
+
+```css
+&lt;%# For persisted objects %&gt;
+&lt;%= resources_scope_color_css("status", ::Status) %&gt;
+&lt;%= resources_scope_color_css("priority", ::IssuePriority) %&gt;
+&lt;%= resources_scope_color_css("type", ::Type, inline_foreground: true) %&gt;
+
+&lt;%# For non-persisted objects %&gt;
+&lt;% Meetings::Statuses::AVAILABLE.each do |meeting_status| %&gt;
+ &lt;%= resource_color_css("meeting_status", meeting_status) %&gt;
+&lt;% end %&gt;
+```
### Code structure
@@ -53,9 +82,10 @@ The status button can be called directly
items = [
OpPrimer::StatusButtonOption.new(name: "Closed",
icon: :lock,
- color: Color.new(hexcode: "#00FF00"),
+ color_ref: 1,
+ color_namespace: "status",
tag: :a,
- href: :a)
+ href: "/bar")
]
component = OpPrimer::StatusButtonComponent.new(current_status: items.first,
items: items,
@@ -64,3 +94,7 @@ The status button can be called directly
end
%&gt;
```
+
+Further, you can pass all options you'd want to pass to the `ActionMenu` item, e.g the description:
+
+<%= embed OpPrimer::StatusButtonComponentPreview, :with_description %>
diff --git a/lookbook/previews/op_primer/status_button_component_preview.rb b/lookbook/previews/op_primer/status_button_component_preview.rb
index 91003490809..2e26660c35f 100644
--- a/lookbook/previews/op_primer/status_button_component_preview.rb
+++ b/lookbook/previews/op_primer/status_button_component_preview.rb
@@ -4,7 +4,7 @@ module OpPrimer
# @logical_path OpenProject/Primer
class StatusButtonComponentPreview < ViewComponent::Preview
# See the [component documentation](/lookbook/pages/components/status_button) for more details.
- # @display min_height 200px
+ # @display min_height 100px
# @param readonly [Boolean]
# @param disabled [Boolean]
# @param size [Symbol] select [small, medium, large]
@@ -35,7 +35,7 @@ module OpPrimer
end
# See the [component documentation](/lookbook/pages/components/status_button) for more details.
- # @display min_height 200px
+ # @display min_height 100px
def with_icon(size: :medium)
status = OpPrimer::StatusButtonOption.new(name: "Open",
color_ref: :open,
@@ -59,15 +59,19 @@ module OpPrimer
end
# See the [component documentation](/lookbook/pages/components/status_button) for more details.
- # @display min_height 200px
+ # @display min_height 150px
def with_description(size: :medium)
status = OpPrimer::StatusButtonOption.new(name: "Open",
+ color_ref: :open,
+ color_namespace: :meeting_status,
icon: :unlock,
description: "The status is open")
items = [
status,
OpPrimer::StatusButtonOption.new(name: "Closed",
+ color_ref: :closed,
+ color_namespace: :meeting_status,
icon: :lock,
description: "The status is closed")
]