Skip to content

Commit 50022d9

Browse files
authored
Merge branch 'fable-hub:feliz_v3.0' into feliz_v3.0
2 parents 3cbfc39 + 92fca4c commit 50022d9

34 files changed

Lines changed: 864 additions & 269 deletions

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"fable": {
6-
"version": "5.0.0-alpha.14",
6+
"version": "5.0.0-alpha.15",
77
"commands": [
88
"fable"
99
],

CONTRIBUTING.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# I want to contribute! What should i do?
2+
3+
Thats awesome! There are many ways you can contribute to the Feliz project:
4+
5+
1. 🏷️ Start by creating an issue of your planned changes. This allows us to discuss the changes before you start working on them and ensure that they are aligned with the project goals.
6+
2. 🛠️ Fork the repository and create a new branch for your changes.
7+
- Check out the section below to find the most important instructions for setting up your development environment.
8+
3. ✨ Make your changes and ensure that you follow the coding style and conventions used in the project. (Styling should be automatically applied by Fantomas if you use VS Code with Ionide)
9+
4. ✅ Write tests for your changes to ensure that they work as expected and do not introduce any regressions.
10+
5. 📚 Document your changes!
11+
- Every Feliz-.fsproj has a related "CHANGELOG" file. Add your changes following the instructions inside the file!
12+
13+
Please use the following base structure for your changelog entries:
14+
15+
`<the-cool-and-awesome-changes-you-did> <#any-related-issue-or-pr-number> (by <@your-github-username>)`
16+
17+
- Write/Update documentation under `./docs`!
18+
6. 📄 Create a pull request with a clear description of your changes and the issue it addresses.
19+
20+
---
21+
22+
# Setting up your development environment
23+
24+
## Requirements
25+
26+
1. [.NET SDK 8.0 or later](https://dotnet.microsoft.com/en-us/download)
27+
2. [Node.js 20 or later](https://nodejs.org/)
28+
29+
## Setup
30+
31+
1. Clone the repository
32+
2. Install dependencies: `dotnet run --project ./build/Build.fsproj setup`.
33+
34+
<details>
35+
36+
<summary>Alternatively, you can manually install the dependencies:</summary>
37+
38+
- NPM dependencies:
39+
40+
```bash
41+
npm install
42+
```
43+
44+
- .NET dependencies:
45+
46+
```bash
47+
dotnet restore
48+
```
49+
50+
- .NET tools:
51+
52+
```bash
53+
dotnet tool restore
54+
```
55+
56+
</details>
57+
58+
3. Verify correct setup by running the tests `dotnet run --project ./build/Build.fsproj test`
59+
4. Ready! 🎉
60+
61+
62+
# Workflows
63+
64+
Feliz uses a f# build project to run common tasks such as testing. You can find the entrypoint for the build project under `./build/Build.fsproj`.
65+
66+
> [!TIP]
67+
> **On Windows** you can also use `.\build.cmd` to run the build tasks instead of `dotnet run --project ./build/Build.fsproj`.
68+
> **On MacOS/Linux** you can also use `./build.sh` to run the build tasks instead of `dotnet run --project ./build/Build.fsproj`.
69+
70+
## Testing
71+
72+
```bash
73+
dotnet run --project ./build/Build.fsproj test
74+
```
75+
76+
## Run docs
77+
78+
1. Go into docs folder:
79+
80+
```bash
81+
cd docs
82+
```
83+
84+
2. Start docs server:
85+
86+
```bash
87+
npm run start
88+
```
File renamed without changes.

docs/docs/api-docs/Contributing.md

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,89 +5,11 @@ sidebar_position: 10
55

66
# Contributing
77

8-
If you are enjoying the Feliz project, consider contributing back and helping out with the community. There are many ways you can contribute, the first of which is to simply use Feliz in your project and report issues you come across whether there are missing style properties or properties that were incorrectly implemeneted.
8+
**We need your help!** We actually do! Feliz is an open-source project and thrives thanks to the contributions from the community. Whether it's fixing bugs, adding new features, improving documentation, or suggesting ideas, we need your help to make Feliz even better.
99

10-
# I want to contribute! What should i do?
10+
Do not shy away from contributing just because you think you are "not experienced enough".
1111

12-
Thats awesome! There are many ways you can contribute to the Feliz project:
12+
Check out the [CONTRIBUTING.md](https://github.com/fable-hub/Feliz/blob/master/CONTRIBUTING.md) file in the repository and get in contact with us via the issues ❤️!
1313

14-
1. 🏷️ Start by creating an issue of your planned changes. This allows us to discuss the changes before you start working on them and ensure that they are aligned with the project goals.
15-
2. 🛠️ Fork the repository and create a new branch for your changes.
16-
- Check out the section below to find the most important instructions for setting up your development environment.
17-
3. ✨ Make your changes and ensure that you follow the coding style and conventions used in the project. (Styling should be automatically applied by Fantomas if you use VS Code with Ionide)
18-
4. ✅ Write tests for your changes to ensure that they work as expected and do not introduce any regressions.
19-
5. 📚 Document your changes!
20-
- Every Feliz-.fsproj has a related "CHANGELOG" file. Add your changes following the instructions inside the file!
21-
- Write/Update documentation under `./docs`!
22-
6. 📄 Create a pull request with a clear description of your changes and the issue it addresses.
2314

24-
---
25-
26-
# Setting up your development environment
27-
28-
## Requirements
29-
30-
1. [.NET SDK 8.0 or later](https://dotnet.microsoft.com/en-us/download)
31-
2. [Node.js 20 or later](https://nodejs.org/)
32-
33-
## Setup
34-
35-
1. Clone the repository
36-
2. Install dependencies: `dotnet run --project ./build/Build.fsproj setup`.
37-
38-
<details>
39-
40-
<summary>Alternatively, you can manually install the dependencies:</summary>
41-
42-
- NPM dependencies:
43-
44-
```bash
45-
npm install
46-
```
47-
48-
- .NET dependencies:
49-
50-
```bash
51-
dotnet restore
52-
```
53-
54-
- .NET tools:
55-
56-
```bash
57-
dotnet tool restore
58-
```
59-
60-
</details>
61-
62-
3. Verify correct setup by running the tests `dotnet run --project ./build/Build.fsproj test`
63-
4. Ready! 🎉
64-
65-
66-
# Workflows
67-
68-
Feliz uses a f# build project to run common tasks such as testing. You can find the entrypoint for the build project under `./build/Build.fsproj`.
69-
70-
:::info
71-
- **On Windows** you can also use `.\build.cmd` to run the build tasks instead of `dotnet run --project ./build/Build.fsproj`.
72-
- **On MacOS/Linux** you can also use `./build.sh` to run the build tasks instead of `dotnet run --project ./build/Build.fsproj`.
73-
:::
74-
75-
## Testing
76-
77-
```bash
78-
dotnet run --project ./build/Build.fsproj test
79-
```
80-
81-
## Run docs
82-
83-
1. Go into docs folder:
84-
85-
```bash
86-
cd docs
87-
```
88-
89-
2. Start docs server:
9015

91-
```bash
92-
npm run start
93-
```

docs/docs/api-docs/feliz/conditional-rendering.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Conditional Rendering
3-
sidebar_position: 3
3+
sidebar_position: 4
44
---
55

66
import ComponentRender from '@site/src/components/ComponentRender';
@@ -18,7 +18,7 @@ You can use any F# pattern normally used for conditional logic in your React com
1818
import ConditionalRendering from '../../feliz-docs/fableoutput/Examples/Feliz/ConditionalRendering'
1919
import RawConditionalRendering from '!!raw-loader!../../feliz-docs/Examples/Feliz/ConditionalRendering.fs'
2020

21-
<ComponentRender code={RawConditionalRendering}>
21+
<ComponentRender code={RawConditionalRendering} defaultOpen>
2222
<ConditionalRendering />
2323
</ComponentRender>
2424

docs/docs/api-docs/feliz/fsharp-in-html.mdx

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,54 @@ In the following example we define a simple button component that takes a text p
1212
import FSharpExample from '../../feliz-docs/fableoutput/Examples/Feliz/FSharp'
1313
import RawFSharpExample from '!!raw-loader!../../feliz-docs/Examples/Feliz/FSharp.fs'
1414

15-
<ComponentRender code={RawFSharpExample}>
15+
<ComponentRender code={RawFSharpExample} defaultOpen>
1616
<FSharpExample text={"Hello from F#"}/>
1717
</ComponentRender>
1818

19-
- We define the button size as discriminated union type.
20-
21-
```FSharp
22-
type ISize =
23-
| Small
24-
| Medium
25-
| Large
26-
```
27-
- We make size an optional parameter with a default value.
28-
29-
```FSharp
30-
static member Example(text: string, onClick: Browser.Types.MouseEvent -> unit, ?size: ISize) =
31-
let size = defaultArg size Medium
32-
33-
```
34-
35-
:::info
36-
Because of this we create the component as `static member` of a class. Using `let` bindings does not allow for optional parameters
37-
:::
38-
39-
- We use a `match case` on `size` to determine the appropriate CSS class to apply.
40-
41-
```fsharp
42-
let sizeClass =
43-
match size with
44-
| Small -> "sm"
45-
| Medium -> ""
46-
| Large -> "lg"
47-
```
48-
49-
- We define a function and pass it to the `onClick` event handler.
50-
51-
```fsharp
52-
let fn = fun _ -> Browser.Dom.console.log("Button clicked!")
53-
// ...
54-
Button.Example("Submit", fn, size = Large)
55-
```
19+
## Discriminated Unions
20+
21+
We define the button size as discriminated union type.
22+
23+
```FSharp
24+
type ISize =
25+
| Small
26+
| Medium
27+
| Large
28+
```
29+
30+
## Optional Parameters
31+
32+
We make size an optional parameter with a default value.
33+
34+
```FSharp
35+
static member Example(text: string, onClick: Browser.Types.MouseEvent -> unit, ?size: ISize) =
36+
let size = defaultArg size Medium
37+
38+
```
39+
40+
:::info
41+
Because of this we create the component as `static member` of a class. Using `let` bindings does not allow for optional parameters
42+
:::
43+
44+
## Pattern Matching
45+
46+
We use a `match .. with` on `size` to determine the appropriate CSS class to apply.
47+
48+
```fsharp
49+
let sizeClass =
50+
match size with
51+
| Small -> "sm"
52+
| Medium -> ""
53+
| Large -> "lg"
54+
```
55+
56+
## Lambda Functions
57+
58+
We define a function and pass it to the `onClick` event handler.
59+
60+
```fsharp
61+
let fn = fun _ -> Browser.Dom.console.log("Button clicked!")
62+
// ...
63+
Button.Example("Submit", fn, size = Large)
64+
```
5665

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: Passing props to components
3+
description: How to pass props to Feliz components
4+
sidebar_position: 2
5+
---
6+
7+
import ComponentRender from '@site/src/components/ComponentRender';
8+
import Example from '../../feliz-docs/fableoutput/Examples/Feliz/PassingProps'
9+
import RawExample from '!!raw-loader!../../feliz-docs/Examples/Feliz/PassingProps.fs'
10+
11+
In Feliz you can pass props to components in a similar way as you would in React with JSX. Props are simply function parameters that you define in your component function.
12+
13+
## Example
14+
15+
<ComponentRender code={RawExample} defaultOpen>
16+
<Example />
17+
</ComponentRender>
18+
19+
## Passing Children
20+
21+
In JSX syntax you typically pass children between the opening and closing tags of a component.
22+
23+
```JSX
24+
<MyButton onClick={handleClick}>
25+
Click Me
26+
</MyButton>
27+
```
28+
29+
This behavior is mimicked in Feliz by defining a `children` parameter in your component function. You can then pass the children as an argument when calling the component.
30+
31+
```fsharp
32+
[<ReactComponent(true)>]
33+
let MyButton(children: ReactElement, onClick: unit -> unit, props: IReactProperty list) =
34+
Html.button [
35+
prop.style [
36+
style.padding 10
37+
style.backgroundColor.lightBlue
38+
style.borderRadius 5
39+
style.cursor.pointer
40+
]
41+
prop.onClick (fun _ -> onClick())
42+
yield! props // same as `...props` in JSX. Can overwrite existing props
43+
prop.children children
44+
]
45+
```
46+
47+
48+
## Spreading props
49+
50+
You can also spread additional props using the `yield!` syntax inside the `prop` list. This allows you to pass any number of additional properties to the component, similar to the spread operator (`...props`) in JSX. Be aware that spreading props can overwrite existing props if there are conflicts.
51+
52+
::::info
53+
54+
When using prop spreading, be cautious as it can lead to unintended overwrites of existing props, which may cause unexpected behavior in your components.
55+
56+
In a list of properties, the last occurrence of a property takes precedence. Therefore, if you spread props after defining specific properties, the spread props can overwrite those specific properties.
57+
58+
:::danger
59+
The exception to this rule is the `children` property. For children the first occurrence takes precedence.
60+
:::
61+
62+
::::
63+
64+
65+
:::tip
66+
It is recommended to define most arguments explicitly for better type safety and clarity. Use spreading only when necessary.
67+
:::
68+
69+
```fsharp
70+
[<ReactComponent(true)>]
71+
let MyButton(children: ReactElement, props: IReactProperty list) =
72+
Html.button [
73+
yield! props // same as `...props` in JSX. Can overwrite existing props
74+
]
75+
```

0 commit comments

Comments
 (0)