Skip to content

[playground] New context example with element that both consumes and provides #1315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 15, 2024

Conversation

augustjk
Copy link
Member

@augustjk augustjk commented Mar 12, 2024

Example is taken from the React doc https://react.dev/learn/passing-data-deeply-with-context
which is also an excellent resource for describing what context does and when to use it.

My only concern with this is that it's such a direct copy of the React doc example, even if I attribute to them at the top of the preview page.

my-heading.ts gets a manually made .js file because we don't have a good transform for the @consume() decorator.

latest preview link: http://localhost:5415/playground/#sample=examples/context-consume-provide

Copy link

github-actions bot commented Mar 12, 2024

A live preview of this PR will be available at the URL(s) below.
The latest URL will be appended to this comment on each push.
Each build takes ~5-10 minutes, and will 404 until finished.

https://pr1315-b3ec3bf---lit-dev-5ftespv5na-uc.a.run.app/
https://pr1315-ce8ea65---lit-dev-5ftespv5na-uc.a.run.app/
https://pr1315-8ed5b34---lit-dev-5ftespv5na-uc.a.run.app/
https://pr1315-29766b3---lit-dev-5ftespv5na-uc.a.run.app/
https://pr1315-5e2261d---lit-dev-5ftespv5na-uc.a.run.app/
https://pr1315-f086a29---lit-dev-5ftespv5na-uc.a.run.app/

@augustjk augustjk force-pushed the new-context-example branch from d107641 to b3ec3bf Compare March 12, 2024 23:34
@e111077
Copy link
Collaborator

e111077 commented Mar 12, 2024

Does this get rendered anywhere on the site so I can play around with the TS / JS slider?

nevermind, found https://pr1315-b3ec3bf---lit-dev-5ftespv5na-uc.a.run.app/playground/#sample=examples/context-consume-provide

@e111077
Copy link
Collaborator

e111077 commented Mar 13, 2024

Discussed offline that I think it's not 100% best practice for a user to define a class field _consumer that is not used in the component, but we think it's best not to introduce a "new concept" of constructor + super() call when all the other examples are using class members

@augustjk
Copy link
Member Author

Synced with @justinfagnani offline on how we might make the example more interesting and added a numbering prefix to all the headings.

We had originally talked about doing alternate numbering system based on level like roman numerals, alphabet, arabic number, etc. but I came across this https://typographyforlawyers.com/hierarchical-headings.html and figured simple is better.

},
});

private get _siblingNumber() {
Copy link
Collaborator

@e111077 e111077 Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be a bit weary using this over an <ol> even if it's for the sake of example. What about counting the number of h3s? like <h3>this is the 5th h3</h3> if it doesn't get too complex

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do this kind of numbering with <ol>s?
image

Copy link
Member Author

@augustjk augustjk Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@e111077 e111077 Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AH sorry the preview site didn't finish building and I thought it was simple numbering. This looks good

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this is you can do it across sections of your application though. The example doesn't show it but presumably there'll be content in between the headings and making that entire thing a <li> doesn't seem right? But of course the numbering can still be done with css counter so that does make this example less compelling.

@augustjk augustjk force-pushed the new-context-example branch from 8ed5b34 to 29766b3 Compare March 15, 2024 18:13
@augustjk augustjk force-pushed the new-context-example branch from 5e2261d to f086a29 Compare March 15, 2024 23:21
@augustjk augustjk merged commit 4035bd6 into main Mar 15, 2024
@augustjk augustjk deleted the new-context-example branch March 15, 2024 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants