Skip to content

Commit d8d293b

Browse files
author
Nicolas Garnier
committed
Adding new StyledFirebaseAuth component that incorporates the CSS
1 parent b17e485 commit d8d293b

File tree

5 files changed

+2607
-69
lines changed

5 files changed

+2607
-69
lines changed

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,25 @@ npm install --save firebase
2222
```
2323

2424
In your app:
25-
1. Import the `FirebaseAuth` component from `react-firebaseui` and import `firebase`.
25+
1. Import the `FirebaseAuth` or the `StyledFirebaseAuth` component from `react-firebaseui` and import `firebase`.
2626
2. Configure Firebase as described in [the Firebase Docs](https://firebase.google.com/docs/web/setup).
2727
3. Write a Firebase UI configuration as described in [firebase/firebaseui-web](https://github.com/firebase/firebaseui-web#configuration).
2828
4. Use the `FirebaseAuth` component in your template passing it the **Firebase UI configuration** and a **Firebase Auth instance**.
2929

3030

31-
### Using `FirebaseAuth` with a redirect
31+
### `FirebaseAuth` vs `StyledFirebaseAuth`
32+
33+
There are two components that allow you to add FirebaseUI auth to your application: `FirebaseAuth` and `StyledFirebaseAuth`. The difference is that `FirebaseAuth` has a reference to the Firebase UI CSS (it `requires` the CSS) whereas `StyledFirebaseAuth` includes the CSS directly in its built. For simplicity you should use `StyledFirebaseAuth` and for better performances and build sizes you should use `FirebaseAuth`. `FirebaseAuth` is meant to be used with a CSS/style loader as part of yor webpack built configuration. See the [Packing your app](#packing) section
34+
35+
36+
### Using `StyledFirebaseAuth` with a redirect
3237

3338
Below is an example on how to use `FirebaseAuth` with a redirect upon sign-in:
3439

3540
```js
3641
// Import FirebaseAuth and firebase.
3742
import React from 'react';
38-
import { FirebaseAuth } from 'react-firebaseui';
43+
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
3944
import firebase from 'firebase';
4045

4146
// Configure Firebase.
@@ -65,7 +70,7 @@ class SignInScreen extends React.Component {
6570
<div>
6671
<h1>My App</h1>
6772
<p>Please sign-in:</p>
68-
<FirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()}/>
73+
<StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()}/>
6974
</div>
7075
);
7176
}
@@ -79,7 +84,7 @@ Below is an example on how to use `FirebaseAuth` with a state change upon sign-i
7984
```js
8085
// Import FirebaseAuth and firebase.
8186
import React from 'react';
82-
import { FirebaseAuth } from 'react-firebaseui';
87+
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
8388
import firebase from 'firebase';
8489

8590
// Configure Firebase.
@@ -120,7 +125,7 @@ class SignInScreen extends React.Component {
120125
<div>
121126
<h1>My App</h1>
122127
<p>Please sign-in:</p>
123-
<FirebaseAuth uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
128+
<StyledFirebaseAuth uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
124129
</div>
125130
);
126131
}
@@ -147,16 +152,19 @@ render() {
147152
<div>
148153
<h1>My App</h1>
149154
<p>Please sign-in:</p>
150-
<FirebaseAuth uiCallback={ui => ui.disableAutoSignIn()} uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
155+
<StyledFirebaseAuth uiCallback={ui => ui.disableAutoSignIn()} uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
151156
</div>
152157
);
153158
}
154159
```
155160

161+
<a href="#packing"/>
156162

157163
## Packing your app
158164

159-
The `FirebaseAuth` component needs a global CSS to get proper styling. The CSS is already imported within `FirebaseAuth`.
165+
If you are using the `StyledFirebaseAuth` component there should not be special configuration needed to package your app since the CSS is already included within the component. if you would like to extract the CSS you should use the `FirebaseAuth` component instead.
166+
167+
The `FirebaseAuth` needs a global CSS to get proper styling. The CSS is already imported within `FirebaseAuth`.
160168
If you are using webpack you'll need to add [CSS loaders](https://github.com/webpack-contrib/css-loader):
161169

162170
```js
@@ -172,6 +180,8 @@ If you are using webpack you'll need to add [CSS loaders](https://github.com/web
172180
}
173181
```
174182

183+
PS: make sure your rule does not exclude `/node_modules/` as this is where the library, and therefore, the CSS is located.
184+
175185
### With ExtractTextPlugin
176186

177187
If you are using [`ExtractTextPlugin`](https://github.com/webpack-contrib/extract-text-webpack-plugin) to extract a CSS file from the required CSS files you would typically use:
@@ -194,6 +204,8 @@ If you are using [`ExtractTextPlugin`](https://github.com/webpack-contrib/extrac
194204
}
195205
```
196206

207+
PS: make sure your rule does not exclude `/node_modules/` as this is where the library, and therefore, the CSS is located.
208+
197209
### With ExtractTextPlugin and CSS modules
198210

199211
If you are using CSS modules in your app you need to handle the CSS files in `/node_modules/` in a separate loader so that they are imported as global CSS files and not modules. Your setup could look like:
@@ -242,7 +254,7 @@ If you are using CSS modules in your app you need to handle the CSS files in `/n
242254

243255
## Styling
244256

245-
To change the styling of the `FirebaseAuth` widget you can override its CSS. You can import a CSS that will be included globally in your packed application. For instance create a `firebaseui-overrides.global.css` file and import it in your app:
257+
To change the styling of the `FirebaseAuth` or the `StyledFirebaseAuth` widget you can override some of its CSS. You can import a CSS that will be included globally in your packed application. For instance create a `firebaseui-overrides.global.css` file and import it in your app:
246258

247259
```js
248260
import './firebaseui-overrides.global.css'; // Import globally.
@@ -258,8 +270,8 @@ If you would like to see an example of styling, have a look at the [example app]
258270
In the case where you would need to load multiple instances of `FirebaseAuth` at the same time you need to set them up with a different ID using the `elementId` attribute. For instance:
259271

260272
```js
261-
<FirebaseAuth elementId="auth_1" uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
262-
<FirebaseAuth elementId="auth_2" uiConfig={this.otherUiConfig} firebaseAuth={firebase.auth()}/>
273+
<StyledFirebaseAuth elementId="auth_1" uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
274+
<StyledFirebaseAuth elementId="auth_2" uiConfig={this.otherUiConfig} firebaseAuth={firebase.auth()}/>
263275
```
264276

265277

0 commit comments

Comments
 (0)