SwiftUI mapping
Every SwiftUI view and modifier this library covers, and the component or prop that stands for it. Sizes are CSS px, which the library treats as points.
Glass and containers
| SwiftUI | @adamexu/glass |
|---|---|
| .glassEffect() | <GlassEffect width={w} height={h}> |
| .frame(width: w, height: h) | width={w} height={h} |
| .glassEffect(.clear.tint(c).interactive(), in: .circle) | <GlassEffect glass={{ variant: "clear", tint: c, interactive: true }} shape={{ type: "circle" }}> |
| .glassEffect(in: .rect(cornerRadius: 16)) | <GlassEffect shape={{ type: "rect", cornerRadius: 16 }}> |
| .rect(cornerRadius: 16, style: .circular) | shape={{ type: "rect", cornerRadius: 16, style: "circular" }} |
| .glassEffect(.identity) | <GlassEffect glass={{ variant: "identity" }}> |
| GlassEffectContainer(spacing: 20) | <GlassEffectContainer spacing={20}> |
| withAnimation(.bouncy) | animation="bouncy" |
| .glassEffectID(id, in: ns) | id={id} |
| .glassEffectUnion(id: u, namespace: ns) | union={u} |
| .glassEffectTransition(.materialize) | transition="materialize" |
| Settings > Liquid Glass > Tint Amount | <GlassProvider tintAmount> |
| .preferredColorScheme(.dark) | <GlassProvider scheme="dark"> |
| @Environment(\.colorScheme) | useGlassSettings().scheme |
Controls
| SwiftUI | @adamexu/glass |
|---|---|
| Toggle(isOn:) | <Toggle isOn onChange> |
| Toggle("Wi-Fi", isOn:) | <Toggle isOn onChange>Wi-Fi</Toggle> |
| Slider(value:in:step:) | <Slider value onChange in step> |
| Slider(...) minimumValueLabel: maximumValueLabel: | <Slider minimumValueLabel maximumValueLabel> |
| Slider(..., onEditingChanged:) | onEditingChanged |
| Slider(..., neutralValue:) | neutralValue |
| Slider(...) ticks: | ticks |
| .sliderThumbVisibility(.hidden) | thumbHidden |
| Picker(selection:).pickerStyle(.segmented) | <SegmentedPicker segments selection onChange> |
| Text("Day").tag("day") in a segmented Picker | { value: "day", label: "Day" } |
| .fixedSize() on a segmented Picker | fixed |
| .buttonStyle(.glass) / .glassProminent | <Button buttonStyle="glass"> / "glassProminent" |
| .buttonStyle(.glass(.clear)) | <Button buttonStyle="glass" glass="clear"> |
| .controlSize(.large) | controlSize="large" |
| .buttonBorderShape(.circle) | borderShape="circle" |
| Button(role: .destructive) | role="destructive" |
| Button("Add", systemImage:) | <Button icon={Plus}>Add</Button> |
| .labelStyle(.iconOnly) | labelStyle="iconOnly" |
| .tint(.orange) | tint="orange" |
| Stepper(title, value:, in:, step:) | <Stepper value onChange in step>title</Stepper> |
| Stepper(title) { } onDecrement: { } | <Stepper onIncrement onDecrement>title</Stepper> |
| ProgressView() | <ProgressView /> |
| ProgressView(value:, total:) { label } currentValueLabel: { } | <ProgressView value total currentValueLabel>label</ProgressView> |
| .progressViewStyle(.circular / .linear) | progressViewStyle="circular" / "linear" |
| Gauge(value:, in:) { label } currentValueLabel: { } | <Gauge value in currentValueLabel>label</Gauge> |
| .gaugeStyle(.accessoryCircular) | gaugeStyle="accessoryCircular" |
| .tint(Gradient(colors: [a, b])) on a Gauge | tint={[a, b]} |
| withAnimation { value = x } on a Gauge | animated |
| Link(title, destination:) | <Link destination>title</Link> |
| .environment(\.openURL, OpenURLAction { }) | openURL |
| .labelsHidden() | labelsHidden |
| .disabled(true) | disabled |
Text input
| SwiftUI | @adamexu/glass |
|---|---|
| TextField("Name", text: $name) | <TextField title="Name" text onTextChange> |
| TextField(..., prompt: Text("...")) | prompt="..." |
| TextField(..., axis: .vertical).lineLimit(3...6) | <TextField axis="vertical" lineLimit={[3, 6]}> |
| .textFieldStyle(.roundedBorder / .plain) | textFieldStyle="roundedBorder" / "plain" |
| LabeledContent("Label") { TextField(...) } | <TextField label="Label"> |
| .onSubmit { } | onSubmit |
| SecureField("Password", text:) | <SecureField title="Password" text onTextChange> |
| TextEditor(text:).frame(minHeight: 120) | <TextEditor minHeight={120}> |
Pickers
| SwiftUI | @adamexu/glass |
|---|---|
| Picker(title, selection:) { } | <Picker title options selection onChange> |
| .pickerStyle(.segmented / .menu / .navigationLink / .wheel) | pickerStyle="segmented" / "menu" / "navigationLink" / "wheel" |
| DatePicker(title, selection:, in:, displayedComponents:) | <DatePicker selection onChange in displayedComponents>title</DatePicker> |
| .datePickerStyle(.compact / .graphical / .wheel) | datePickerStyle="compact" / "graphical" / "wheel" |
| ColorPicker(title, selection:, supportsOpacity:) | <ColorPicker selection onChange supportsOpacity>title</ColorPicker> |
Presentations
| SwiftUI | @adamexu/glass |
|---|---|
| .alert(title, isPresented:) { actions } message: { } | <Alert title message actions isPresented onDismiss> |
| Button(title, role: .destructive / .cancel) { } in a presentation | { title, role: "destructive" / "cancel", action } |
| TextField(placeholder, text:) in an alert | field={{ placeholder, value, onChange }} |
| .confirmationDialog(title, isPresented:, titleVisibility:) { } message: { } | <ConfirmationDialog title titleVisibility message actions isPresented onDismiss> |
| the view a dialog or popover is attached to | source={ref} (an element, or a Frame) |
| .popover(isPresented:, arrowEdge:) { content } | <Popover source isPresented onDismiss arrowEdge> |
| .presentationCompactAdaptation(.popover / .sheet) | compactAdaptation="popover" / "sheet" |
| .sheet(isPresented:) { } | <Sheet isPresented onDismiss> |
| .presentationDetents([.medium, .large], selection:) | <Sheet detents={["medium", "large"]} selectedDetent onSelectedDetentChange> |
| .presentationDetents([.fraction(0.3), .height(300)]) | detents={[{ fraction: 0.3 }, { height: 300 }]} |
| .presentationDragIndicator(.visible) | dragIndicator="visible" |
| .presentationCornerRadius(r) / .presentationBackground(c) | cornerRadius={r} / background={c} |
| .interactiveDismissDisabled() | interactiveDismissDisabled |
| .presentationContentInteraction(.scrolls) | contentInteraction="scrolls" |
| .presentationSizing(.form / .page / .fitted) | sizing="form" / "page" / { fittedHeight } |
| .fullScreenCover(isPresented:) { } | <FullScreenCover isPresented onDismiss> |
Menus
| SwiftUI | @adamexu/glass |
|---|---|
| Menu("Options") { Button(...) } | <Menu label="Options"><MenuButton title action> |
| Menu { } label: { } / .menuOrder(.fixed) | <Menu renderSource={...}> / order="fixed" |
| Button(title, role: .destructive) { } in a menu | <MenuButton title role="destructive" action> |
| Toggle(title, isOn:) in a menu | <MenuToggle title isOn onChange> |
| Divider() / Section("Title") in a menu | <MenuDivider /> / <MenuSection title="Title"> |
| Menu("More") inside a menu | <Submenu title="More"> |
| ControlGroup { }.controlGroupStyle(.compactMenu / .menu) | <MenuControlGroup size="small" / "medium"> |
| .contextMenu { } preview: { } | <ContextMenu menu={...} preview={...}> |
| Picker(selection:) { }.pickerStyle(.menu) | <MenuPicker options selection onChange> |
| .buttonStyle(.plain) on a Menu in a List | <Menu buttonStyle="none"> |
Navigation and lists
| SwiftUI | @adamexu/glass |
|---|---|
| NavigationStack(path:) { root }.navigationDestination(for:) | <NavigationStack root path onPathChange destination> |
| .navigationTitle / .navigationSubtitle | <NavigationPage title subtitle> |
| .navigationBarTitleDisplayMode(.inline) | titleDisplayMode="inline" |
| .scrollEdgeEffectStyle(.soft, for: .top) / .scrollEdgeEffectHidden() | scrollEdgeEffectStyle="soft" / scrollEdgeEffectHidden |
| ToolbarItem(placement: .topBarTrailing) { Button } | <ToolbarItem placement="topBarTrailing" title icon={Plus} onAction> |
| ToolbarItemGroup / ToolbarSpacer(.fixed) | <ToolbarItemGroup> / <ToolbarSpacer sizing="fixed"> |
| .buttonStyle(.borderedProminent) in a toolbar | prominent |
| .sharedBackgroundVisibility(.hidden) | sharedBackground={false} |
| Menu in a ToolbarItem | menu={MenuNode[]} |
| .navigationBarBackButtonHidden() | backButtonHidden |
| .searchable | searchable |
| NavigationLink(value:) | <NavigationLink value> in a List, <NavigationStackLink value> outside |
| @Environment(\.dismiss) / path | useNavigation() |
| .listStyle(.plain) | listStyle="plain" |
| Form { } | <Form> |
| ForEach.onDelete / .onMove | <Section onDelete onMove> |
| \.editMode / List(selection:) | editMode="active" / selection onSelectionChange |
| .swipeActions(edge: .leading) | <SwipeActions leading={[{ title, role, tint, icon, onAction }]}> |
| Label("Wi-Fi", systemImage:) / LabeledContent("Name", value:) | <Label title icon> / <LabeledContent title value> |
| Toggle("Wi-Fi", isOn:) in a List | <Toggle isOn onChange><Text>Wi-Fi</Text></Toggle> |
| Button("Delete", role: .destructive) in a List | <Button role="destructive"> (no buttonStyle) |
Tab view
| SwiftUI | @adamexu/glass |
|---|---|
| TabView(selection:) | <TabView selection onSelectionChange> |
| Tab("Home", systemImage: "house", value: 0) | <Tab value={0} title="Home" icon={<House />}> |
| Tab(role: .search) | <Tab role="search"> |
| .badge(3) | badge={3} |
| TabSection("Albums") | <TabSection title="Albums"> |
| .tabViewStyle(.sidebarAdaptable) | tabViewStyle="sidebarAdaptable" |
| .tabBarMinimizeBehavior(.onScrollDown) | minimizeBehavior="onScrollDown" |
| .tabViewBottomAccessory { } | bottomAccessory={...} |
| .tabViewCustomization($c) | customization |
| .customizationID / .customizationBehavior | customizationId / customizationBehavior |
| .tabPlacement(.sidebarOnly) | tabPlacement="sidebarOnly" |
| .defaultVisibility(.hidden, for: .tabBar) | defaultVisibility="hidden" |
| .defaultTabBarPlacement(.sidebar) | defaultTabBarPlacement="sidebar" |