Dedicated component to document API references #9498
Replies: 5 comments 3 replies
-
This is an amazing initiative and analysis, @ArmandPhilippot ! I would be very open to a component that was easy to author! |
Beta Was this translation helpful? Give feedback.
-
Should we support cases where there are multiple types, like I did a first test by retrieving the content of each On large screens, it is not a problem. On small screens (like a smartphone), however, the display is not great: I did a second test keeping the list (so only one (I can display |
Beta Was this translation helpful? Give feedback.
-
Another edge case: custom badges. In Content collections, we have a So, I see two options:
In this specific case, it's not too annoying since the functionality disappears in v5 if I don't make a mistake. But maybe this case appears elsewhere or may be necessary in the future. |
Beta Was this translation helpful? Give feedback.
-
Sorry that I'm just catching up with this now.. I haven't yet read through here entirely and I have scanned the PR. First of all, thank you @ArmandPhilippot for taking the initiative here to help devs add their content in an easier way! And secondly, nothing is going to happen until Chris is back to contribute to this discussion. 😄 Just want to point out a bit of authoring weirdness from the PR:
I think this is a less intuitive solution when just Since and Type were previously on their own, and when combined, I think it makes it actually harder to read and see clearly what's going on? I think maybe where a new component makes sense is something like I will also note that as you said, we do not author config reference directly, but rather we get HTML from the source file. That means we don't need a component there, and I think it would be worse to ask translators to use a component rather than just copy exactly what they see in the file they're translating? So I don't think any component on that page makes sense. I'm sorry if this sounds more negative than encouraging! But I'm trying to figure out exactly when/where this improves the authoring experience. I do think the "prompting devs to fill in the attributes of the component" is helpful, and they don't need to know about that leading blank line etc. But looking at the replacements in the PR, in most places the source now makes less sense and is less readable. So I fear this may be a "component because we can" rather than something that is yet truly helpful. What do you think, now that you've crafted something and seen it in use? |
Beta Was this translation helpful? Give feedback.
-
Just wanted to leave a quick comment and say that I expect to have time to loop Chris in on this in the coming week! |
Beta Was this translation helpful? Give feedback.
-
The format used to document each item on References pages is now documented in DocsDocs.
Proposition: dedicated component
@florian-lefebvre has suggested on Discord to create a dedicated component to handle the formatting. For example:
Instead of:
I think this is a great idea to:
Type:
andDefault:
become UI strings likeAdded in:
there is nothing left to translate)However, we might still need an empty line to avoid a potential bug when rendering Markdown passed as a child.
The empty line after
<p>
was made "official" after a discussion with Chris in a previous PR. To quote him:So the component should be used this way:
In practice, I haven't seen any rendering bugs without this line... so either things have changed, or it's a rare bug. So I don't know if we should be strict about the empty line.
What we need
A component that handles formatting to reduce the effort of writers when they have to fill in the type, default value and version.
<Since />
<slot />
because some of them might contain links.Implementation
I made some tests using the following component:
That seems to do the trick! Well, almost...
In this implementation I expect "Default:" to always be a code so we can retrieve it from a property and put it in a
<code />
tag. This is not always the case. At the moment I'm not sure how to handle this:<code />
tag then useset:html
...About the implementation: We need an extra element to render the slot due to
Astro.slots.has
limitations.Astro.slots.has("default")
always returnstrue
. So we need to render the slot and check if the result exists (""
is falsy).Also, we could update the
docgen
script to use this component. I saw that it uses aCLI
field, so we should add that to the component.I've never worked with RTL languages so... is there anything we can add to the component to make sure it renders properly in those languages? (i.e. is the order the same?) I wanted to check on the Arabic pages, but it seems the references are not translated. On the other hand, the current
<Since />
component doesn't seem to do anything for layout so I guess it should be ok.Naming
I'm not sure about the component name...
docgen
)Default:
or a<Since />
is useful...So
<ApiReferenceType />
doesn't seem adequate and maybe a bit long. What do you think of<ApiMeta />
or maybe just<Meta />
? If you have any other suggestions, I'm all ears! 😄Optional proposition: evolve the syntax
While I was writing the code, I realized that this was a perfect case (semantically) to use
<dl />
instead of some<br />
and<strong />
tags. The output would look like:<div />
is valid as direct child of<dl />
so we don't need<br />
anymore<dt />
is bold<dt />
/<dd />
couple is rendered inlineset:html
directly to<dd />
to render the Type.Pros:
If in RTL languages the order is reversed, it might be easier to control this.
Caveats:
If we do this,
<Since />
should no longer be used alone or it should be wrapped with<dl />
because we need to update its syntax. Also, the code will no longer be valid in translated pages (while waiting for translators).I see two solutions:
<Since />
is in use. I can give it a try but I'm not comfortable with most of the languages so... reviewers will be welcome! And maybe updating translated pages should be done in a separate PR (withI18nIgnore
) but merged at the same time as the other one.<Since />
component in our new component and wait until<Since />
disappears from the documentation to remove it or to update our component code with an updated<Since />
component.Beta Was this translation helpful? Give feedback.
All reactions