-
Notifications
You must be signed in to change notification settings - Fork 432
core: ✨ add new package space-header #752
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
Conversation
packages/space-header/tsconfig.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this file shorter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@@ -0,0 +1,11 @@ | |||
export const inject_to_body = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we should add a class name or id, to make it easier for devs to change the position within the page?
that way they don't have to change their underlying app/page design in case the header gets in the way of something (toolbar etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @jbilcke nice idea!
i tried with both, class name or id, and I decided to go for the ID while className is probably not clear enough, tailwind class will not work etc.. so easier for us to target it through their own CSS file
thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh got it!
I missed the box.setAttribute("id", "huggingface-space-header");
all good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related: I think we should allow users to provide a "target" and if so, rather than appending to body
, append to that target.
Like with Svelte: (but same for any other framework)
https://svelte.dev/docs/client-side-component-api#creating-a-component
eg init(space, {target: "..."})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coyotte508 should be good now! tell me if you had something different in mind 🤗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mind it was more of a string that can be passed to document.querySelector
, but a HTMLElement
works too
packages/space-header/src/index.ts
Outdated
@@ -0,0 +1,23 @@ | |||
import { inject_to_body} from "./inject_to_body" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could add a prettifier to have unified spaces / semicolons, but that's just code-smetics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code was on another project before (without prettier), so should be good now!
Thank you @enzostvs for doing this! for some context I had started my own independent version based on Tailwind (my goal was to stay close to the original using Tailwind ie. save time in case the original design changes, let tailwind generate a tiny optimized stylesheet, let the framework generate a tiny static .js code injector etc - I would have put it into its own standalone module not just my ai stories factory app) but I never finished as I got involved in other things, and I think you approach works fine too (this header shouldn't change that often).. plus no dependencies which is great! 👌 |
Thanks for this PR, looks great, just have a few questions from a gradio PoV, where we may not know the user and space name up front.
|
…he function to avoid the request to the HF API
@pngwn just pushed a change to cover your first point, now you can pass the
|
Amazing. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great from the gradio side! Thanks @enzostvs!
Yes, you will use the Spaces env variables to check whether the Gradio app is running on Spaces, correct, @pngwn? |
@julien-c yus! We will also hide when embedded via the web component I think as the space info is already in the wrapper. One case we may not be able to figure out is if someone embeds using an iframe. I'm not sure what we want to do in that case, should we just show it? |
you mean the gradio app runs on Spaces, but the raw URL like https://julien-c-coqui.hf.space is embedded in an iframe on a different website? I would display it in that case yes (but no strong opinion) |
Add the
mini header
into your project if running on a custom/sub domainExample:
Must be called once the page has been mounted. If this is not the case, a log error is displayed to prevent the user
we've decided to stick with vanilla JS, which may evolve if necessary. (web component, etc)