Skip to content

Commit

Permalink
Ensured all Cookbook examples work (#384) (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
EstebenR authored Jan 15, 2025
1 parent 29fc29a commit 3f2d6d4
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 142 deletions.
1 change: 1 addition & 0 deletions docs/examples/cookbook/animated-computed.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local Players = game:GetService("Players")

local Fusion = -- initialise Fusion here however you please!
local scoped = Fusion.scoped
local peek = Fusion.peek
local Children = Fusion.Children

local TWEEN_INFO = TweenInfo.new(
Expand Down
17 changes: 8 additions & 9 deletions docs/examples/cookbook/button-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clicking.

This should be a generally useful template for assembling components of your
own. For further ideas and best practices for building components, see
[the Components tutorial](../../../tutorials/components/components).
[the Components tutorial](../../tutorials/best-practices/components).


-----
Expand All @@ -13,7 +13,7 @@ own. For further ideas and best practices for building components, see

```Lua linenums="1"
local Fusion = -- initialise Fusion here however you please!
local scoped = Fusion.scoped
local peek = Fusion.peek
local Children, OnEvent = Fusion.Children, Fusion.OnEvent
type UsedAs<T> = Fusion.UsedAs<T>

Expand Down Expand Up @@ -73,9 +73,8 @@ local function Button(
if use(props.Disabled) then COLOUR_BG_DISABLED
elseif use(isHeldDown) then COLOUR_BG_HELD
elseif use(isHovering) then COLOUR_BG_HOVER
else return COLOUR_BG_REST
end
end),
else COLOUR_BG_REST
end),
BG_FADE_SPEED
),

Expand Down Expand Up @@ -111,11 +110,11 @@ local function Button(
end,

[Children] = {
New "UICorner" {
scope:New "UICorner" {
CornerRadius = ROUNDED_CORNERS
},

New "UIPadding" {
scope:New "UIPadding" {
PaddingTop = PADDING.Y,
PaddingBottom = PADDING.Y,
PaddingLeft = PADDING.X,
Expand Down Expand Up @@ -159,12 +158,12 @@ local function Button(

The `scope` parameter specifies that the component depends on Fusion's methods.
If you're not sure how to write type definitions for scopes,
[the 'Scopes' section of the Components tutorial](../../../tutorials/components/components/#scopes)
[the 'Scopes' section of the Components tutorial](../../tutorials/best-practices/components#scopes)
goes into further detail.

The property table is laid out with each property on a new line, so it's easy to
scan the list and see what properties are available. Most are typed with
[`UsedAs`](../../../api-reference/state/types/usedas), which allows the user to
[`UsedAs`](../../api-reference/state/types/usedas), which allows the user to
use state objects if they desire. They're also `?` (optional), which can reduce
boilerplate when using the component. Not all properties have to be that way,
but usually it's better to have the flexibility.
Expand Down
Loading

0 comments on commit 3f2d6d4

Please sign in to comment.