Skip to content

Commit 9ec36c0

Browse files
committed
Add froact.list config for custom key
1 parent 6e65001 commit 9ec36c0

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

froact.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ end
3939

4040
-- stylua: ignore
4141
type ListConfig = (
42-
{ orderByName: boolean?, setOrder: true, initial: number?, }
43-
| { orderByName: boolean?, setOrder: false?, initial: nil }
42+
{ orderByName: boolean?, setOrder: true, initial: number?, key: string? }
43+
| { orderByName: boolean?, setOrder: false?, initial: nil, key: string? }
4444
)
4545
local function newList(roact)
4646
return function(config: ListConfig, elements: { [number]: Element })
@@ -68,7 +68,10 @@ local function newList(roact)
6868
then "Instance"
6969
else "None"
7070

71-
local instanceName = className .. " " .. count[className]
71+
local instanceName = if config.key
72+
and element.props[config.key]
73+
then element.props[config.key]
74+
else className .. " " .. count[className]
7275
if config.orderByName and sortType ~= "None" then
7376
index += 1
7477
instanceName = string.format(nameFormat, index, instanceName)

froactful.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ end
4040

4141
-- stylua: ignore
4242
type ListConfig = (
43-
{ orderByName: boolean?, setOrder: true, initial: number?, }
44-
| { orderByName: boolean?, setOrder: false?, initial: nil }
43+
{ orderByName: boolean?, setOrder: true, initial: number?, key: string? }
44+
| { orderByName: boolean?, setOrder: false?, initial: nil, key: string? }
4545
)
4646
local function newList(roact)
4747
return function(config: ListConfig, elements: { [number]: Element })
@@ -69,7 +69,10 @@ local function newList(roact)
6969
then "Instance"
7070
else "None"
7171

72-
local instanceName = className .. " " .. count[className]
72+
local instanceName = if config.key
73+
and element.props[config.key]
74+
then element.props[config.key]
75+
else className .. " " .. count[className]
7376
if config.orderByName and sortType ~= "None" then
7477
index += 1
7578
instanceName = string.format(nameFormat, index, instanceName)
@@ -190,8 +193,8 @@ function froact.configure<Hooks>(config: {
190193
)
191194
local function applyEvent(props: any, tags: { any })
192195
for _, tag in tags do
193-
props[(config.Roact.Event :: any)[tag]] = props["on" .. tag]
194-
props["on" .. tag] = nil
196+
props[(config.Roact.Event :: any)[tag]] = props["on"..tag]
197+
props["on"..tag] = nil
195198
end
196199
end
197200
-- stylua: ignore start
@@ -396,3 +399,4 @@ function froact.configure<Hooks>(config: {
396399
end
397400

398401
return froact
402+

0 commit comments

Comments
 (0)