mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-21 04:57:57 +01:00
21b4095dfd
Upstream 04/17/2026 fixes https://github.com/Bubberstation/Bubberstation/issues/5549 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com> Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com> Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com> Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com> Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com> Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com> Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com> Co-authored-by: loganuk <fakeemail123@aol.com> Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com> Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com> Co-authored-by: Lucy <lucy@absolucy.moe> Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com> Co-authored-by: Isratosh <Isratosh@hotmail.com> Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com> Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com> Co-authored-by: Alexander V. <volas@ya.ru> Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com> Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> Co-authored-by: Cameron Lennox <killer65311@gmail.com> Co-authored-by: Tim <timothymtorres@gmail.com> Co-authored-by: Iamgoofball <iamgoofball@gmail.com> Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com> Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com> Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com> Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com> Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com> Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com> Co-authored-by: Josh <josh.adam.powell@gmail.com> Co-authored-by: Josh Powell <josh.powell@softwire.com> Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com> Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com> Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com> Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
83 lines
3.2 KiB
Markdown
83 lines
3.2 KiB
Markdown
# Chat Embedded Components
|
|
|
|
Have you ever embedded html into tgui chat? Maybe just css stuff like `<span class='alien'> </span>`?
|
|
Have you ever wanted to embed tgui components instead? For styling or ease of use of course.
|
|
|
|
Well we have a system for that! You can pass component information in via html attributes, and it'll be rendered in chat.
|
|
How? Let's get into it.
|
|
|
|
## How it works
|
|
|
|
Here's a sample span that embeds a tooltip around the wrapped text.
|
|
|
|
`<span data-component=\"Tooltip\" data-content=\"Hey it works!\">Does it work?</span>`
|
|
|
|
There's two components here, let's break them down.
|
|
|
|
### Targeting a component
|
|
|
|
Telling tgui chat what component you want to render is really simple. You just embed its name in the data-component attribute.
|
|
|
|
You saw it before, but for reference,
|
|
`<div data-component=\"Tooltip\"></div>`
|
|
this tells the div to render a tooltip.
|
|
|
|
There is a bit of nuance here however.
|
|
|
|
We can't embed components that haven't been prewhitelisted.
|
|
|
|
This isn't because of security concerns or anything, we just can't lookup components by their name without creating a lookup table.
|
|
You can find that in [tgui chat's renderer](../packages/tgui-panel/chat/renderer.tsx) under the name `TGUI_CHAT_COMPONENTS`
|
|
|
|
Adding a new component is simple, just add its name to the dictionary, and import it into the file.
|
|
|
|
### Sending props
|
|
|
|
Ok, so we know how to render a component, but that's nearly useless unless we also know how to send extra info alongside it.
|
|
|
|
So how's that work?
|
|
|
|
The syntax is similar to sending a component, but has a bit more caveats.
|
|
We have two bits of info to contend with. The name of the prop, and its value.
|
|
First then, how do you send the name of a prop?
|
|
|
|
#### Sending a prop's name
|
|
|
|
`<span {component setting} data-content={value}></span`
|
|
|
|
It's really simple, just another data attribute, with the name you want to refer to the property by.
|
|
|
|
Something important to note here, data attribute names cannot contain any upper case chars, or anything that isn't XML compatible.
|
|
|
|
Because of this, we need to do another map of sent name -> intended name. This can also be found in the [renderer file](../packages/tgui-panel/chat/renderer.tsx) with the name `TGUI_CHAT_ATTRIBUTES_TO_PROPS`
|
|
|
|
#### Sending a prop's value
|
|
|
|
Setting a prop's value is as simple as giving the data-content attribute a string value.
|
|
|
|
This does mean that we can only send strings to javascript. Because of this, we do some parsing js side to pull out other values you may want to send.
|
|
|
|
There's three supported datatypes.
|
|
|
|
##### **Booleans**
|
|
|
|
Booleans are send by sending a string in the form
|
|
`data-bool=\"$true\"` and "`data-bool=\"$false\"`
|
|
The $ char is included to allow you to send the string "true" without breaking anything.
|
|
|
|
Please keep this restriction in mind.
|
|
|
|
##### **Numbers**
|
|
|
|
Numbers are simpler then the above. If you send a string with no whitespace that can be parsed as an int or float, it will be.
|
|
|
|
So `data-int=\"-10\"` will be parsed as `-10`
|
|
|
|
`data-float=\"10.2\"` will also be correctly handled, treated as `10.2`
|
|
|
|
##### **Strings**
|
|
|
|
Strings are the most simple. If a value is passed to an html attribute, and it doesn't meet any of the above requirements, it will be
|
|
|
|
`data-string=\"hey man, it works!\"`
|